﻿#include "stdafx.h"
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <math.h>


#define pi 3.141592654

using namespace std;


class Method
{
public:
	Method(void);
	~Method(void);
	 
	 vector<string> contentArr;
	 string kindOfTool;
	 string getTheNum(string contentOfRegionScr, string parameter);
	 string getTheNum(string contentOfRegionScr, string parameter, int count);
	 string getTheNum(string contentOfRegionScr, string parameter,string spliter1, string spliter2 );
	 string getTheNum(string contentOfRegionScr, string parameter,string spliter1, string spliter2 ,bool isSeriousValue);
	 vector<string> getTheNum(string content,int index_operation,int index_profile);
	 bool isContain(string contentOfRegionScr, string parameter);
	 vector<string> split(string contentOfRegionScr, string parameter);
	 int numOfTooth(string contentOfRegionScr);
	 string readScr(string scrPth);
	 vector<int> findOperationNum(string content, string operationName);
	 vector<int> findOperationNums(string contentOfRegionScr, string operationName);
	 vector<int> findProfileNum(string content, string operationName, string operation , int operation_Num);
	 double getSeriesValue(string contentOfRegionScr,string parameter);
	 string getSeriesValue(string contentOfRegionScr,vector<int> operationNum, string operationName,string parameter, double offsetValue,string judgeSentence,bool isRotate);
	 string getSteptoolsString(string contentOfRegionScr, string parameter, double T_valueOfCode, double value,double multiple,string judgeSentence,bool isRotate,bool isOffsetPoint);
	 string getTheNum(string contentOfRegionScr, string parameter,string spliter1 ,int numindex);
	 int creatScrFile(string pathToWrite,string content);
	 bool is_T_Tool(string content);
	 vector<vector<string>> getSteptoolStruct(string content);
	 string rOffset(string content,string parameter,double offsetValue,string judgeSentence,bool isRotate,int flag,bool isArc_top);
	 string programOffset(string content,vector<int> operationNum, string operationName,string parameter,string offsetPosition, double offsetValue,bool ofssetAll,string judgeSentence,bool isRotate);
}; 


Method::Method(void)
{
}


Method::~Method(void)
{
}




string Method::readScr(string scrPth)
{	
	ifstream inFile;
	inFile.open(scrPth);
	string s;
	string content;
	while(getline(inFile,s))
	{
		content+=s;
	}
	inFile.close();
	return content;
}
int Method::creatScrFile(string pathToWrite,string content)
{
		ofstream outFile(pathToWrite);
		if(outFile)
		{		
			outFile<<content<<endl;		
        	outFile.close();
		    return 1;
		}
		else
		{
			return 0; 
		}
}

double Method::getSeriesValue(string contentOfRegionScr,string parameter)
{
	int index=0;
    double value=0;
	value=atof(getTheNum(contentOfRegionScr,parameter, "," , ")" , true).c_str());	
    return value;           
}

vector<int> Method::findOperationNum(string contentOfRegionScr, string operationName)
{
	int operationCount = 0;
	vector<int> oprationNum;	
	for(unsigned int index=0;index<contentArr.size();index++)
	{
		if(isContain(contentArr[index],"addOperation"))
		{
			operationCount++;			
		}	
	}
	
	for(int i=0;i<operationCount;i++)
	{
		int num=0;
		num=contentOfRegionScr.find("."+ to_string(i)+ "." + operationName+".");
		if(num>0)
		{
			oprationNum.push_back(i);
		}
	}
	return oprationNum;
}
vector<int> Method::findOperationNums(string contentOfRegionScr, string operationName)
{
	vector<int> operationNums;
	int index=0;
	int flag=-1;
	
	while (!isContain(contentArr[index],"! Set up any broken parameter links"))
	{
		if(isContain(contentArr[index],"addOperation"))
		{
			flag++;
		}
		if(isContain(contentArr[index],"addOperation(\""+operationName+"\")"))
		{
			operationNums.push_back(flag);
		}
		index++;
	}
	return operationNums;
}
vector<int> Method::findProfileNum(string contentOfRegionScr, string operationName, string operation , int operation_Num)
{
	int operationCount = 0;
	vector<int> oprationNum;	
	for(unsigned int index=0;index<(contentArr.size());index++)
	{
		if(isContain(contentArr[index],"addOperation"))
		{
			operationCount++;
		}		
	}
	for(int i=0;i<operationCount;i++)
	{
		int num=0;
		num=contentOfRegionScr.find("."+ to_string(operation_Num) + "." + operation +"."+ to_string(i)+ "." + operationName);
		if(num>0)
		{
			oprationNum.push_back(i);
		}
	}
	return oprationNum;
}

string Method::getSeriesValue(string contentOfRegionScr,vector<int> operationNum, string operationName,string parameter, double offsetValue,string judgeSentence,bool isRotate)
{
	
	int index=0;
    double value=0;
	string operation;
	string spliter;
	string offsetContent;
	for (int index = 0; index < operationNum.size(); index++)
	{
		vector<string> splitSentence;
		string judgeSentence_copy = judgeSentence;
		string parameter_copy =parameter;
		operation = to_string(operationNum[index]);
		int num = parameter_copy.find("operation");
		parameter_copy.replace(num,9,operation);
		
		if(isContain(contentOfRegionScr,parameter_copy))
		{
			value=atof(getTheNum(contentOfRegionScr,parameter_copy, "," , ")" , true).c_str());
			offsetValue = offsetValue + value ;
			if (judgeSentence != "")
			{
				int index_operation = judgeSentence_copy.find("operation");
				while (index_operation>0)
				{
					judgeSentence_copy.replace(index_operation,9,operation);
					index_operation = judgeSentence_copy.find("operation");
				}
				if (spliter != "")
				{
					splitSentence = split(judgeSentence_copy,spliter);
				}		
				else
				{			
					splitSentence.push_back(judgeSentence_copy);			
				}

				if (spliter == "||")
				{
					if (isContain(contentOfRegionScr,splitSentence[0]) || isContain(contentOfRegionScr,splitSentence[1]))
					{				 
						offsetContent += "angel=getToolOffset(\""+kindOfTool+"." + operation + "." + operationName + "\"," + "\"a\"" + ");\n";
						if (isRotate)
						{
							offsetContent += "if(angel > 10 && ange < -10) then\n\t";
						}
						else
						{
							offsetContent += "if(angel < 10 && angel > -10) then\n\t";
						}			
						offsetContent += "setSeriesValue(\""+parameter_copy + "," + to_string(offsetValue) + ");\n";
						offsetContent += "ifend\n";
					}
				}				
				else if(spliter == "&&")
				{
					if(isContain(contentOfRegionScr,splitSentence[0]) && isContain(contentOfRegionScr,splitSentence[1]))
					{
						offsetContent += "angel=getToolOffset(\""+kindOfTool+"." + operation + "." + operationName + "\"," + "\"a\"" + ");\n";
						if (isRotate)
						{
							offsetContent += "if(angel > 10 && ange < -10) then\n\t";
						}
						else
						{
							offsetContent += "if(angel < 10 && angel > -10) then\n\t";
						}			
						offsetContent += "setSeriesValue(\""+parameter_copy + "," + to_string(offsetValue) + ");\n";
						offsetContent += "ifend\n";
					}
				}
				else
				{
					if(isContain(contentOfRegionScr,splitSentence[0]))
					{
						offsetContent += "angel=getToolOffset(\""+kindOfTool+"." + operation + "." + operationName + "\"," + "\"a\"" + ");\n";
						if (isRotate)
						{
							offsetContent += "if(angel > 10 && ange < -10) then\n\t";
						}
						else
						{
							offsetContent += "if(angel < 10 && angel > -10) then\n\t";
						}			
						offsetContent += "setSeriesValue(\""+parameter_copy + "," + to_string(offsetValue) + ");\n";
						offsetContent += "ifend\n";
					}
				}
			}
			else
			{
				offsetContent += "angel=getToolOffset(\""+kindOfTool+"." + operation + "." + operationName + "\"," + "\"a\"" + ");\n";
				if (isRotate)
				{
					offsetContent += "if(angel > 10 && ange < -10) then\n\t";
				}
				else
				{
					offsetContent += "if(angel < 10 && angel > -10) then\n\t";
				}			
				offsetContent += "setSeriesValue(\""+parameter_copy + "," + to_string(offsetValue) + ");\n";
				offsetContent += "ifend\n";
			}															
		}
	}
	return offsetContent;           
}

string Method::getSteptoolsString(string contentOfRegionScr, string parameter, double T_valueOfCode, double value,double multiple,string judgeSentence,bool isRotate,bool isOffsetPoint)
{
	 string offsetContent;
     string operation ;
	 string profile;
     double offsetValue = (value - T_valueOfCode) / multiple;
	 vector<int> operationNum;
	 vector<vector<string>> steptoolStruct=getSteptoolStruct(contentOfRegionScr);
	 vector<int> profileNum;
	 string spliter;
	 if(judgeSentence != "")
	 {
		int index = judgeSentence.find("||");				
		if(index <= 0)
		{
			index = judgeSentence.find("&&");
			if (index<=0)
			{				
				spliter = "" ;
			}
			else
			{
				spliter = "&&" ;
			}
		}
		else
		{
			spliter = "||" ;
		}		
	}	
	if(isOffsetPoint)
	{
		for (int i = 0; i < steptoolStruct[2].size()/2; i++)
		{
			operation = steptoolStruct[2][2*i];
			profile = steptoolStruct[2][2*i+1];
			string addline_part =kindOfTool+"."+operation+".f_steptools."+profile+".st_profile\", ";
				int index =0 ;
				for (index = 0; index < contentArr.size(); index++)
				{
					if(isContain(contentArr[index],addline_part))break;
				}
				string addline_up =contentArr[index];
				vector<string> splitStr_up = split(addline_up,",");
				vector<string> splitStr_up2 = split(splitStr_up[4],")");
				string addline_dowm =contentArr[index+2];
				vector<string> splitStr_down = split(addline_dowm,",");
				vector<string> splitStr_down2 = split(splitStr_down[4],")");
				if (atof(steptoolStruct[3][i*4].c_str())-atof(steptoolStruct[3][i*4+2].c_str())>0)
				{
					
					if(offsetValue >0)
					{
						steptoolStruct[3][i*4+3] = to_string(atof(steptoolStruct[3][i*4+3].c_str()) + offsetValue/2);
					}
					else
					{
						steptoolStruct[3][i*4+3] = to_string(atof(steptoolStruct[3][i*4+3].c_str()) + offsetValue/2);
					}
				}
				else
				{
					if(offsetValue >0)
					{						
						steptoolStruct[3][i*4+1] = to_string(atof(steptoolStruct[3][i*4+1].c_str()) + offsetValue/2);
					}
					else
					{
						steptoolStruct[3][i*4+1] = to_string(atof(steptoolStruct[3][i*4+1].c_str()) + offsetValue/2);
					}
				}			
				splitStr_up[4] = steptoolStruct[3][1]+");";
				addline_up = splitStr_up[0]+","+splitStr_up[1]+","+splitStr_up[2]+","+splitStr_up[3]+","+splitStr_up[4];
				splitStr_down[2] = steptoolStruct[3][3];
				addline_dowm = splitStr_down[0]+","+splitStr_down[1]+","+splitStr_down[2]+","+splitStr_down[3]+","+splitStr_down[4]+";";
				string addline_middle = "addLineToGeometry(\""+kindOfTool+"."+operation+".f_steptools."+profile+".st_profile\","+steptoolStruct[3][4*i]+"," +steptoolStruct[3][4*i+1]+","+ steptoolStruct[3][4*i+2]+","+ steptoolStruct[3][4*i+3]+");";
				offsetContent += "angel=getToolOffset(\""+kindOfTool+"." + operation + ".f_steptools." + profile + ".st_profile" + "\"," + "\"a\"" + ");\n";
				if (isRotate)
				{
					offsetContent += "if(angel > 10 && ange < -10) then\n\t";
				}
				else
				{ 
					offsetContent += "if(angel < 10 && angel > -10) then\n\t";
				}		
				offsetContent+="clearGeometry(\""+kindOfTool+"."+operation+".f_steptools."+profile + ".st_profile\");\n\t"+addline_up+"\n\t"
					+ addline_middle +"\n\t"+addline_dowm+"\n\t"+"executeOperationInstruction(\""+kindOfTool+"."+operation+".f_steptools."+profile+".st_profile\", \"convertElementsToLeads\");\n";
				offsetContent += "ifend\n";
		}
		
	}
	else
	{
		for (int index_i = 0; index_i < steptoolStruct[2].size()/2; index_i++)
		{		 
			string judgeSentence_copy = judgeSentence;
		    operation=operationNum[2*index_i];
			vector<string> splitSentence;
		    profile=profileNum[2*index_i+1];
			if(judgeSentence_copy != "")
			{
				int index_operation = judgeSentence_copy.find("operation");
				int index_profile = judgeSentence_copy.find("profile");
				while (index_operation>0)
				{
					judgeSentence_copy.replace(index_operation,9,operation);
					judgeSentence_copy.replace(index_profile,7,profile);
					index_operation = judgeSentence_copy.find("operation");
					index_profile = judgeSentence_copy.find("profile");
				}
				if (spliter != "")
				{
					splitSentence = split(judgeSentence_copy,spliter);
				}		
				else
				{			
					splitSentence.push_back(judgeSentence_copy);			
				}

				if (spliter == "||")
				{
					if (isContain(contentOfRegionScr,splitSentence[0]) || isContain(contentOfRegionScr,splitSentence[1]))
					{
						offsetContent += "angel=getToolOffset(\""+kindOfTool+"." + operation + ".f_steptools." + profile + ".st_profile" + "\"," + "\"a\"" + ");\n";
						offsetContent += "primaryValue=get(\""+kindOfTool+"." + operation + ".f_steptools." + profile + ".st_profile."+ parameter + "\");" + "\n";
						if (isRotate)
						{
							offsetContent += "if(angel > 10 && ange < -10) then\n\t";
						}
						else
						{ 
							offsetContent += "if(angel < 10 && angel > -10) then\n\t";
						}		
							offsetContent +=  "set(\""+kindOfTool+"." + operation + ".f_steptools." + profile + ".st_profile."+ parameter + "\"," + "primaryValue+" + to_string(offsetValue) + " );" + "\n";
							offsetContent += "ifend\n";
					}
			    }
			    else if(spliter == "&&")
				{
					if (isContain(contentOfRegionScr,splitSentence[0]) && isContain(contentOfRegionScr,splitSentence[1]))
					{
						offsetContent += "angel=getToolOffset(\""+kindOfTool+"." + operation + ".f_steptools." + profile + ".st_profile" + "\"," + "\"a\"" + ");\n";
						offsetContent += "primaryValue=get(\""+kindOfTool+"." + operation + ".f_steptools." + profile + ".st_profile."+ parameter + "\");" + "\n";
						if (isRotate)
						{
							offsetContent += "if(angel > 10 && ange < -10) then\n\t";
						}
						else
						{ 
							offsetContent += "if(angel < 10 && angel > -10) then\n\t";
						}		
						offsetContent +=  "set(\""+kindOfTool+"." + operation + ".f_steptools." + profile + ".st_profile."+ parameter + "\"," + "primaryValue+" + to_string(offsetValue) + " );" + "\n";
						offsetContent += "ifend\n";
					}
				}
				else
				{
					if (isContain(contentOfRegionScr,splitSentence[0]))
					{
						offsetContent += "angel=getToolOffset(\""+kindOfTool+"." + operation + ".f_steptools." + profile + ".st_profile" + "\"," + "\"a\"" + ");\n";
						offsetContent += "primaryValue=get(\""+kindOfTool+"." + operation + ".f_steptools." + profile + ".st_profile."+ parameter + "\");" + "\n";
						if (isRotate)
						{
							offsetContent += "if(angel > 10 && ange < -10) then\n\t";
						}
						else
						{ 
							offsetContent += "if(angel < 10 && angel > -10) then\n\t";
						}		
						offsetContent +=  "set(\""+kindOfTool+"." + operation + ".f_steptools." + profile + ".st_profile."+ parameter + "\"," + "primaryValue+" + to_string(offsetValue) + " );" + "\n";
						offsetContent += "ifend\n";
					}
				}
			}
			else
			{
				offsetContent += "angel=getToolOffset(\""+kindOfTool+"." + operation + ".f_steptools." + profile + ".st_profile" + "\"," + "\"a\"" + ");\n";	
				offsetContent += "primaryValue=get(\""+kindOfTool+"." + operation + ".f_steptools." + profile + ".st_profile."+ parameter + "\");" + "\n";
				if (isRotate)
				{
					offsetContent += "if(angel > 10 && ange < -10) then\n\t";
				}
				else
				{
						offsetContent += "if(angel < 10 && angel > -10) then\n\t";
				}		
				offsetContent +=  "set(\""+kindOfTool+"." + operation + ".f_steptools." + profile + ".st_profile."+ parameter + "\"," + "primaryValue+" + to_string(offsetValue) + " );" + "\n";
				offsetContent += "ifend\n";
			}					
		}
	}
	return offsetContent;
}


string Method::rOffset(string content,string parameter,double offsetValue,string judgeSentence,bool isRotate,int flag,bool isArc_top)
{
	string offsetContent;
	vector<vector<string>> stepStruct = getSteptoolStruct(content);
	string operation;
	string profile;
	unsigned int index = 0;      
	
	for (index = 0; index < stepStruct[flag].size()/2; index++)
    {
		string judgeSentence_copy = judgeSentence;
		operation = stepStruct[flag][2*index];
		profile = (stepStruct[flag][2*index+1]);
		if(flag == 0)
		{
			string Arc_strar = getTheNum(content,"addArcToGeometry(\""+kindOfTool +"."+operation+".f_steptools."+ profile +".st_profile",",",4);
			bool judge =false;
			if (isArc_top)
			{
				judge = (Arc_strar == " 0.000");
			}
			else
			{
				judge = (Arc_strar !=" 0.000");
			}
			    if (judge)
				{
					offsetContent += "angel=getToolOffset(\""+kindOfTool+"." + operation + ".f_steptools." + profile + ".st_profile" + "\"," + "\"a\"" + ");\n";
					offsetContent += "primaryValue=get(\""+kindOfTool+"." + operation + ".f_steptools." + profile + ".st_profile."+ parameter + "\");" + "\n";
					if (isRotate)
					{
						offsetContent += "if(angel > 10 && ange < -10) then\n\t";
					}
					else
					{
						offsetContent += "if(angel < 10 && angel > -10) then\n\t";
					}		
					offsetContent +=  "set(\""+kindOfTool+"." + operation + ".f_steptools." + profile + ".st_profile."+ parameter + "\"," + "primaryValue+" + to_string(offsetValue) + " );" + "\n";
					offsetContent += "ifend\n";
				}		
		}
		else
		{
			int index_operation = judgeSentence_copy.find("operation");
			int index_profile = judgeSentence_copy.find("profile");
			while (index_operation>0)
			{
				judgeSentence_copy.replace(index_operation,9,operation);
				judgeSentence_copy.replace(index_profile,7,profile);
				index_operation = judgeSentence_copy.find("operation");
				index_profile = judgeSentence_copy.find("profile");
			}
			if(isContain(content,judgeSentence))
			{
				offsetContent += "angel=getToolOffset(\""+kindOfTool+"." + operation + ".f_steptools." + profile + ".st_profile" + "\"," + "\"a\"" + ");\n";
				offsetContent += "primaryValue=get(\""+kindOfTool+"." + operation + ".f_steptools." + profile + ".st_profile."+ parameter + "\");" + "\n";
				if (isRotate)
				{
					offsetContent += "if(angel > 10 && ange < -10) then\n\t";
				}
				else
				{
					offsetContent += "if(angel < 10 && angel > -10) then\n\t";
				}		
				offsetContent +=  "set(\""+kindOfTool+"." + operation + ".f_steptools." + profile + ".st_profile."+ parameter + "\"," + "primaryValue+" + to_string(offsetValue) + " );" + "\n";
				offsetContent += "ifend\n";
			}
			
		}
    }            
	return offsetContent;
}


int Method::numOfTooth(string contentOfRegionScr)
{
	int num = 0;
	num=atoi(getTheNum(contentOfRegionScr, "set(\""+kindOfTool + ".no_of_fl\", ").c_str());
    return num;
}
string Method::getTheNum(string contentOfRegionScr, string parameter)
{
	string num="" ;
	int n = contentOfRegionScr.find(parameter);
    if (n > 0)
    {
		num = contentOfRegionScr.substr((n+parameter.length()), 1);
    }
	return num;        
}
string Method::getTheNum(string contentOfRegionScr, string parameter, int count)
{
	string num="";
    int n = contentOfRegionScr.find(parameter);
    if (n > 0)
    {
		if (count > 0)
        {
			num = contentOfRegionScr.substr(n + parameter.length(), count);
        }
        else
        {
            num = contentOfRegionScr.substr(n+count, 1);
        }                
    }
   return num;
}
string Method::getTheNum(string contentOfRegionScr, string parameter,string spliter1, string spliter2 )
{
	string num="";
	int index=1;
	string spiltedStr;
	for(index=0;index<(contentArr.size());index++)
	{
		if(isContain( contentArr[index], parameter))break;
	}	
	vector<string> splitString2;
	splitString2=split(contentArr[index],spliter1);	
	if(spliter2!="")
	{
		vector<string> splitString3=split(splitString2[1],spliter2);
		num=splitString3[0];
	}
	else
	{
		num=splitString2[1];		
	}
	
	return num;
}
string Method::getTheNum(string contentOfRegionScr, string parameter,string spliter1, string spliter2 ,bool isSeriousValue)
{
	string num="";
	int index=1;
	string spiltedStr;
	for(index=0;index<(contentArr.size());index++)
	{
		if(isContain(contentArr[index], parameter))break;
	}
	vector<string> splitString2;
	splitString2=split(contentArr[index],spliter1);	
	if(spliter2!=""&&isSeriousValue)
	{
		vector<string> splitString3=split(splitString2[2],spliter2);
		num=splitString3[0];
	}
	else
	{
		num=splitString2[1];
	}
	return num;
}

string Method::getTheNum(string contentOfRegionScr, string parameter,string spliter1,int numindex)
{
	string num="";
	int index=1;
	string spliter2;
	string spiltedStr;
	for(index=0;index<(contentArr.size());index++)
	{
		if(isContain(contentArr[index], parameter))break;
	}
	vector<string> splitString2;
	splitString2=split(contentArr[index],spliter1);	
	if(numindex==5)
	{
		spliter2=")";
		vector<string> splitString3=split(splitString2[5],spliter2);
		num=splitString3[0];
	}
	else
	{
		num=splitString2[numindex];
	}
	return num;
}
vector<string> Method::getTheNum(string content,int index_operation,int index_profile)
{
	vector<string> numOfSteptool;
	vector<string> splitStr1=split(content,".");
	numOfSteptool.push_back(splitStr1[index_operation]);
	if(index_profile>0)
	{
		numOfSteptool.push_back(splitStr1[index_profile]);
	}	
	return numOfSteptool;
}




bool Method::isContain(string content, string parameter)
{
	int index=0;
	index=content.find(parameter);
	if(index>=0)
	{
		return true;
	}
	else
	{
		return false;
	}
}


vector<string> Method::split(string contentOfRegionScr, string parameter)
{
	int index=1;
	string spiltedStr;
	vector<string> splitString;
	while(index>0)
	{
		index=contentOfRegionScr.find(parameter);
		if(index>0)
		{
			spiltedStr=contentOfRegionScr.substr(0,index);
			contentOfRegionScr=contentOfRegionScr.erase(0,index+1);
			splitString.push_back(spiltedStr);
		}
		else
		{
			splitString.push_back(contentOfRegionScr);
		}
	}
	return splitString;
}

bool Method::is_T_Tool(string content)
{
	bool is_T_Tool=false;
	vector<int> operation=findOperationNums(content,"f_steptools");
	if(operation.size()>0)
	{
		if(isContain(content,"addOperation(\"f_cylindrical\")"))
		{
			is_T_Tool=true;
		}
		else
		{
			int index;
			for(index=0;index<contentArr.size()-4;index++)
			{
				if(isContain(contentArr[index],"addLineToGeometry(\"mill")&&isContain(contentArr[index+1],
					"addLineToGeometry(\"mill")&&isContain(contentArr[index+2],"addLineToGeometry(\"mill")&&isContain(contentArr[index+3],"addLineToGeometry(\"mill"))
				{
					is_T_Tool=true;
				}
			}
		}
	}
	return is_T_Tool;
}

vector<vector<string>> Method::getSteptoolStruct(string content)
{
	vector<vector<string>> SteptoolStruct;
	
	vector<string> Arc_profile;
	vector<string> twoLine_profile;
	vector<string> oneLine_profile;
	vector<string> chamfer_profile;
	
	vector<string> Arc_oneLine;
	vector<string> Point_oneLine;
	int index=0;
	int i=0;
	for (i = 0; i <= contentArr.size()-4; i++)
	{
		if(isContain(contentArr[i],"addArcToGeometry(\"mill"))
		{
			Arc_profile.push_back(getTheNum(contentArr[i],1,3)[0]);
			Arc_profile.push_back(getTheNum(contentArr[i],1,3)[1]);
		}
		else if(isContain(contentArr[i],"addLineToGeometry(\"mill") && isContain(contentArr[i+1],
			"addLineToGeometry(\"mill") && isContain(contentArr[i+2],"addLineToGeometry(\"mill") &&isContain(contentArr[i+3],"addLineToGeometry(\"mill"))
		{
			
			twoLine_profile.push_back(getTheNum(contentArr[i],1,3)[0]);
			twoLine_profile.push_back(getTheNum(contentArr[i],1,3)[1]);
		}
		else
		{
			
			if(isContain(contentArr[i],"addLineToGeometry(\"mill") && isContain(contentArr[i+1],
			"addLineToGeometry(\"mill") && isContain(contentArr[i+2],"addLineToGeometry(\"mill"))
			{
				
				vector<string> splitStr1 = split(contentArr[i+1],",");
				vector<string> splitStr2 = split(splitStr1[4],")");
				double od = atof(getTheNum(content ,"set(\""+kindOfTool+".tool_od\", ",  "," ,  ")").c_str());
				if (abs(atof(splitStr1[2].c_str())-atof(splitStr2[0].c_str())) < 0.005 && abs(od/2-atof(splitStr1[2].c_str())) < 0.01)
				{
					oneLine_profile.push_back(getTheNum(contentArr[i],1,3)[0]);
					oneLine_profile.push_back(getTheNum(contentArr[i],1,3)[1]);
				}
				else
				{
					chamfer_profile.push_back(getTheNum(contentArr[i],1,3)[0]);
					chamfer_profile.push_back(getTheNum(contentArr[i],1,3)[1]);
				}
				Point_oneLine.push_back(splitStr1[1]);
				Point_oneLine.push_back(splitStr1[2]);
				Point_oneLine.push_back(splitStr1[3]);
				Point_oneLine.push_back(splitStr2[0]);
				
 			}
		}
	}

	SteptoolStruct.push_back(Arc_profile);
	SteptoolStruct.push_back(twoLine_profile);
	SteptoolStruct.push_back(oneLine_profile);
	SteptoolStruct.push_back(Point_oneLine);
	
	return SteptoolStruct;
}


string Method::programOffset(string content,vector<int> operationNum, string operationName, string parameter, string offsetPosition, double offsetValue,bool offsetAll,string judgeSentence,bool isRotate)
{
	
	string offsetContent;
	string operation;
	string quotation;
	string get;
	string set;
	int index = 0;
	int num;
	string spliter;
	
	if(offsetAll)
	{
		num = operationNum.size();	
	}
	else
	{		
		num = 1;
		if (isRotate)
		{
			num = 2;
		}
	}	
	if(judgeSentence != "")
	{
		index = judgeSentence.find("||");
		if(index <= 0)
		{
			index = judgeSentence.find("&&");
			if (index<=0)
			{				
				spliter = "" ;				
			}
			else
			{
				spliter = "&&" ;
			}
		}
		else
		{
			spliter = "||" ;
		}
		
	}	
	if(operationNum.size()>0)
	{
		if(offsetPosition!="")
		{
			get = "getWheelOffset";
			set = "setWheelOffset";
			quotation = "\",\"";
		}
		else
		{
			get = "get";
			set = "set";
		}		
		for (unsigned int index = 0; index < num; index++)
		{			
			vector<string> splitSentence;
			string judgeSentence_copy =judgeSentence;
			operation = to_string(operationNum[index]);					
			if(judgeSentence_copy != "")
			{ 				
				int index_operation = judgeSentence_copy.find("operation");
				while (index_operation>0)
				{
					judgeSentence_copy.replace(index_operation,9,operation);
					index_operation = judgeSentence_copy.find("operation");
				}				
				if (spliter != "")
				{
					splitSentence = split(judgeSentence_copy,spliter);
				}		
				else
				{			
					splitSentence.push_back(judgeSentence_copy);					
				}				
				if (spliter == "||")
				{
					if(isContain(content,splitSentence[0]) || isContain(content,splitSentence[1]))
					{					
						offsetContent += "angel=getToolOffset(\""+kindOfTool+"." + operation + "." + operationName + "\"," + "\"a\"" + ");\n";
						offsetContent += "primaryValue="+get+"(\""+kindOfTool+"." + operation + "." + operationName + parameter + quotation + offsetPosition + "\");" + "\n";
						if (isRotate)
						{
							offsetContent += "if(angel > 10 && ange < -10) then\n\t";
						}
						else
						{
							offsetContent += "if(angel < 10 && angel > -10) then\n\t";
						}					
						offsetContent += set+"(\""+kindOfTool+"." + operation + "." + operationName + parameter + quotation + offsetPosition+"\"," + "primaryValue+" + to_string(offsetValue) + ");" + "\n";
						offsetContent += "ifend\n";
					}
				}
				else if (spliter == "&&")
				{
					if(isContain(content,splitSentence[0]) && isContain(content,splitSentence[1]))
					{
						offsetContent += "angel=getToolOffset(\""+kindOfTool+"." + operation + "." + operationName + "\"," + "\"a\"" + ");\n";
						offsetContent += "primaryValue="+get+"(\""+kindOfTool+"." + operation + "." + operationName + parameter + quotation + offsetPosition + "\");" + "\n";
						if (isRotate)
						{
							offsetContent += "if(angel > 10 && ange < -10) then\n\t";
						}
						else
						{
							offsetContent += "if(angel < 10 && angel > -10) then\n\t";
						}					
						offsetContent += set+"(\""+kindOfTool+"." + operation + "." + operationName + parameter + quotation + offsetPosition+"\"," + "primaryValue+" + to_string(offsetValue) + ");" + "\n";
						offsetContent += "ifend\n";					
					}
				}
				else
				{
					if(isContain(content,splitSentence[0]))
					{
						
						offsetContent += "angel=getToolOffset(\""+kindOfTool+"." + operation + "." + operationName + "\"," + "\"a\"" + ");\n";
						offsetContent += "primaryValue="+get+"(\""+kindOfTool+"." + operation + "." + operationName + parameter + quotation + offsetPosition + "\");" + "\n";
						if (isRotate)
						{
							offsetContent += "if(angel > 10 && ange < -10) then\n\t";
						}
						else
						{
							offsetContent += "if(angel < 10 && angel > -10) then\n\t";
						}					
						offsetContent += set+"(\""+kindOfTool+"." + operation + "." + operationName + parameter + quotation + offsetPosition+"\"," + "primaryValue+" + to_string(offsetValue) + ");" + "\n";
						offsetContent += "ifend\n";
					}
				}
			}
			else
			{
				offsetContent += "angel=getToolOffset(\""+kindOfTool+"." + operation + "." + operationName + "\"," + "\"a\"" + ");\n";
				offsetContent += "primaryValue="+get+"(\""+kindOfTool+"." + operation + "." + operationName + parameter + quotation + offsetPosition + "\");" + "\n";
				if (isRotate)
				{
					offsetContent += "if(angel > 10 && ange < -10) then\n\t";
				}
				else
				{
					offsetContent += "if(angel < 10 && angel > -10) then\n\t";
				}					
				offsetContent += set+"(\""+kindOfTool+"." + operation + "." + operationName + parameter + quotation + offsetPosition+"\"," + "primaryValue+" + to_string(offsetValue) + ");" + "\n";
				offsetContent += "ifend\n";
			}									
		}
	}	
	return offsetContent;
}


class CodeOffset
{
public:
	CodeOffset(string content,string kindOfTool);
	~CodeOffset(void);
	string offsetContent;
	string operation;
	double offsetValue;
	string kindsOfTool;
	bool isRotate ;
	vector<int> operationNum;
	vector<int> operationNum_f_od;
	vector<int> operationNum_f_steptools;
	vector<int> operationNum_r_fg;
	vector<int> operationNum_r_fgfm;
	vector<int> operationNum_f_fg;
	vector<int> operationNum_f_odcre;
	vector<int> operationNum_f_cg;
	vector<int> operationNum_f_eg;
	vector<int> operationNum_f_ed;
	vector<int> operationNum_f_ed_nch;
	vector<int> operationNum_r_od_bk;
	vector<int> operationNum_r_fg_lnd;

	Method method;
	bool is_T_Tool;
	string d4_Offset(string contentOfRegionScr,double T_valueOfCode, double value);
	string daozhui_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string beita1_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string F_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string aerfa1_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string e1_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string a1_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string e3_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string aerfaI_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string aerfa2_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string J1_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string S4_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string lambda_1_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string lambda_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string Llambda_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string e_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string h_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string e4_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string dI_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string HX_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string HZ_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string beita_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string pai_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string b_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string Lf_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string L2_1_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string beita2_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string j_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string seita_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string L1_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string k_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string m_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string Dc3_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string f_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string f1_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string f2_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string a_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string S1_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string aerfa3_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string f3_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string d6_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string aerfa4_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string gAL_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string gAS_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string gAM_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string Dc4_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string d5_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string fa4_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string fr4_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string r_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string S2_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string S3_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string h1_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string N_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string L2_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string L3_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string L4_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string lambdae_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string r1_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string e_1_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string L_1_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string f5_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string aerfa9_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string aerfa10_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string aerfa11_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string aerfa12_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string aerfax1_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string aerfax2_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string aerfaz1_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string aerfaz2_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string fb_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string lambdae_1_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
	string JD_Offset(string contentOfRegionScr, double T_valueOfCode, double value);
};
CodeOffset::CodeOffset(string content,string var)
{
	kindsOfTool=var;
	method.contentArr=method.split(content,";");
	method.kindOfTool=kindsOfTool;
	operation = "operation" ;
	isRotate =false;
	
}


CodeOffset::~CodeOffset(void)
{
}
string CodeOffset::d4_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{			
		offsetContent = "";
		offsetValue = -(value - T_valueOfCode)/2;                
		offsetContent+=method.programOffset(contentOfRegionScr,operationNum_r_fgfm,"r_fgfm","","radial",offsetValue,true,"",isRotate);
		offsetContent+=method.programOffset(contentOfRegionScr,operationNum_r_fg,"r_fg","","radial",offsetValue,true,"",isRotate);
		offsetContent+=method.programOffset(contentOfRegionScr,operationNum_f_fg,"f_fg","","radial",offsetValue,true,"",isRotate);			
        return offsetContent;
}
string CodeOffset::daozhui_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{	
		offsetContent = "";
        offsetValue = (value - T_valueOfCode)/2; 
		string get = "primaryValue=get(\""+kindsOfTool+".y_taper_offset\");";
		string set = "set(\""+kindsOfTool+".y_taper_offset\",primaryValue+" + to_string(offsetValue) + ");";             
        offsetContent = get +"\n"+ set + "\n";      
		operationNum = operationNum_f_od;	
		if (operationNum.size() <= 0)
        {                
			offsetContent += method.getSteptoolsString(contentOfRegionScr,"",T_valueOfCode,value,1,"",isRotate,true);
        }
        return offsetContent;
}
string CodeOffset::beita1_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{      
		offsetContent = "";
        offsetValue = -(value - T_valueOfCode);
		 offsetContent += method.programOffset(contentOfRegionScr,operationNum_r_fg,"r_fg",".od_eot_hook","",offsetValue,true,"",isRotate);
		 offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_fg,"f_fg",".od_eot_hook","",offsetValue,true,"",isRotate);
		 offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_fg,"f_fg",".od_shank_hook","",offsetValue,true,"",isRotate);
         return offsetContent;	
}

string CodeOffset::F_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{
	offsetContent = "";
	offsetValue = (value - T_valueOfCode)*10;
	offsetContent += method.programOffset(contentOfRegionScr,operationNum_r_fg,"r_fg",".eot_fg_clr","",offsetValue,false,"",isRotate);
	offsetContent += method.programOffset(contentOfRegionScr,operationNum_r_fg,"r_fg",".shank_fg_clr","",offsetValue,false,"",isRotate);
    return offsetContent;
}

string CodeOffset::aerfa1_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{
	offsetContent = "";
	offsetValue =-(value - T_valueOfCode);
	string judgeSentence1= kindsOfTool+"." + operation + ".f_odcre.grd_section\", 0.000)";
	string judgeSentence2= kindsOfTool+"." + operation + ".f_odcre.grd_section\", 2.000)";
	string judgeSentence = judgeSentence1 + "||" + judgeSentence2;
	if(operationNum_f_od.size()>0)
	{
		offsetContent += method.programOffset(contentOfRegionScr, operationNum_f_od, "f_od",".od_pri_fn", "" , offsetValue,true, "",isRotate);
	}
	if(operationNum_f_odcre.size()>0)
	{
		offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_odcre,"f_odcre",".grd_section", "", offsetValue, true,judgeSentence,isRotate);
	}	
	return offsetContent;
}

string CodeOffset::e1_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{
	offsetContent = "";
    int num = method.numOfTooth(contentOfRegionScr);
    if (num % 2 == 0)
    {
		offsetValue = -(value - T_valueOfCode) / 2;
    }
    else
    {
		offsetValue = (value - T_valueOfCode) / (-1.5);      
    }
	string judgeSentence1= kindsOfTool+"." + operation + ".f_cg.cg_eg_both\", 1";
	string judgeSentence2= kindsOfTool+"." + operation + ".f_cg.cg_eg_both\", 2";
	string judgeSentence = judgeSentence1 + "||" + judgeSentence2;
	offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_eg,"f_eg","","face",offsetValue,true,"",isRotate);
	offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_cg,"f_cg","","face",offsetValue,true,judgeSentence,isRotate);
    return offsetContent;
       

}

string CodeOffset::a1_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{
	offsetContent = "";
	offsetValue = -(value - T_valueOfCode);
	if (method.isContain(contentOfRegionScr,"set(\""+kindsOfTool+".no_of_fl\", 2)"))
	{
		string judgeSentence1 = kindsOfTool+"." + operation + ".f_cg.cg_eg_both\", 1";
		string judgeSentence2 = kindsOfTool+"." + operation + ".f_cg.cg_eg_both\", 2";
		string judgeSentence = judgeSentence1 + "||" + judgeSentence2;
		string judgeSentence3 = kindsOfTool+"." + operation + ".f_eg.walk_gash_rad\", 1.000";
		offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_eg,"f_eg",".short_gash_stop","",offsetValue,true,judgeSentence3,isRotate);
		offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_cg,"f_cg",".short_gash_stop","",offsetValue,true,judgeSentence,isRotate);
	}
	return offsetContent;
}

string CodeOffset::e3_Offset(string contentOfRegionScr, double T_valueOfCode, double value) 
{
	offsetContent = "";	
    double num = 0;
    offsetValue = value - T_valueOfCode;              
	num = atof(method.getTheNum(contentOfRegionScr, "set(\""+kindsOfTool+".cr_rad\"", ",", ")").c_str());
	string judgeSentence1 = kindsOfTool+"." + operation + ".f_cg.cg_eg_both\", 0";
	if (T_valueOfCode < num)
	{	
		offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_cg,"f_cg","","radial",offsetValue,true,judgeSentence1,isRotate);
	}
	else
	{		
		offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_cg,"f_cg","","face",offsetValue,true,judgeSentence1,isRotate);
	}
    return offsetContent;
}
string CodeOffset::aerfaI_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{
	offsetContent = "";
	string content = method.programOffset(contentOfRegionScr,operationNum_f_cg,"f_cg","","a",offsetValue,true,"",isRotate);
	int num = content.find("WheelOffset");
	while( num>= 0)
	{
		content.replace(num,11,"ToolOffset");
		num = content.find("WheelOffset");
	}
	offsetContent = content ;
    return offsetContent;         
}

string CodeOffset::aerfa2_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{
        
                offsetContent = "";
                string get ;
                string set ;
				operationNum=operationNum_f_od;
                offsetValue = -(value - T_valueOfCode);                            
				if (operationNum.size() > 0)
                {
                    operation = method.getTheNum(contentOfRegionScr, ".f_od.pri_or_sec\", 2",-1);
                    if (operation == "")
                    {
                        operation = method.getTheNum(contentOfRegionScr, ".f_od.pri_or_sec\", 0", -1);
                    }
                        get = "primaryValue=get(\""+kindsOfTool+"." + operation + ".f_od.od_sec_fn\");";
                        set = "set(\""+kindsOfTool+"." + operation + ".f_od.od_sec_fn\"," + "primaryValue+" + to_string(offsetValue) + ");";
                        offsetContent = get + "\n" + set + "\n";
                }
				else if(operationNum_f_odcre.size()>0)
 				{
					string judgeSentence1 = kindsOfTool+"." + operation + ".f_odcre.grd_section\", 0.000";
					string judgeSentence2 = kindsOfTool+"." + operation + ".f_odcre.grd_section\", 2.000";
					string judgeSentence = judgeSentence1 + "||" + judgeSentence2;
					offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_odcre,"f_odcre",".od_sec_fn","",offsetValue,true,judgeSentence,isRotate); 
				}
                else
                {
					offsetContent = method.getSteptoolsString(contentOfRegionScr, "st_profile.sec_radial", T_valueOfCode, value, -1,"",isRotate,false);
                }                           												
	return offsetContent;
}
		
string CodeOffset::J1_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{
     offsetContent = "";
	 offsetValue =(value-T_valueOfCode)/2;
	offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_eg,"f_eg",".long_gash_stop","",offsetValue,true,"",isRotate); 
	string judgeSentence1 = kindsOfTool+"." + operation + ".f_cg.cg_eg_both\", 1";
	string judgeSentence2 = kindsOfTool+"." + operation + ".f_cg.cg_eg_both\", 2";
	string judgeSentence = judgeSentence1 + "||" + judgeSentence2;
	offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_cg,"f_cg",".long_gash_stop","",offsetValue,true,judgeSentence,isRotate); 
    return offsetContent;
}

string CodeOffset::S4_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{
    cout<<"***********************"<<endl;
	offsetContent = "";
	offsetValue = -(value - T_valueOfCode);
	int num = method.numOfTooth(contentOfRegionScr);
	string parameter1 = kindsOfTool+"."+operation+".f_eg.walk_length\", 2";
	string parameter2 = kindsOfTool+"."+operation+".f_cg.walk_length\", 2";
	string judgeSentence1 = kindsOfTool+"." + operation + ".f_eg.indiv_flute_option\", true";
	string judgeSentence2 = kindsOfTool+"." + operation + ".f_cg.cg_eg_both\", 1";
	string judgeSentence3 = kindsOfTool+"." + operation + ".f_cg.cg_eg_both\", 2";
	string judgeSentence = judgeSentence2 + "||" +judgeSentence3 ;
	if (num == 3)
	{
		offsetContent += method.getSeriesValue(contentOfRegionScr,operationNum_f_eg,"f_eg",parameter1,offsetValue,judgeSentence1,isRotate);
		offsetContent += method.getSeriesValue(contentOfRegionScr,operationNum_f_cg,"f_cg",parameter2,offsetValue,judgeSentence,isRotate);
	}
	return offsetContent;
         
}

string CodeOffset::lambda_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{
           
                offsetContent = "";
                string get ;
                string set ;
                offsetValue = -(value - T_valueOfCode);
                get = "primaryValue=get(\""+kindsOfTool+".dish\");";
                set = "set(\""+kindsOfTool+".dish\",primaryValue+" + to_string(offsetValue) + ");";
                offsetContent = get + "\n" + set + "\n";
                return offsetContent;                    
}
		
string CodeOffset::lambda_1_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{
                offsetContent = "";
                offsetValue = -(value - T_valueOfCode);
				string judgeSentence = "link(\""+kindsOfTool+".dish\", \""+kindsOfTool+"." + operation + ".f_ed.dish\", false)";
				offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_ed,".f_ed",".dish","",offsetValue,true,judgeSentence,isRotate);
                return offsetContent;        
        }

string CodeOffset::Llambda_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{
                offsetContent = "";
	string judgeSentence = "link(\""+kindsOfTool+".dish\", \""+kindsOfTool+"." + operation + ".f_ed.dish\", false)";
	offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_ed,"f_ed","","face",offsetValue,true,judgeSentence,isRotate);
	return offsetContent;       
}

//這個要改補償砂輪的
string CodeOffset::e_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{
	offsetContent = "";
	if(operationNum_f_eg.size()>0)
	{
		offsetValue = -(value - T_valueOfCode) / 1;
		offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_eg,"f_eg",".eg_a_offset","",offsetValue,true,"",isRotate);
		if (operationNum_f_cg.size()>0)
		{
			if(operationNum_r_fg.size()>0)
			{
				offsetContent += method.programOffset(contentOfRegionScr,operationNum_r_fg,"r_fg","","face",offsetValue,true,"",isRotate);
			}
			if (operationNum_r_fgfm.size()>0)
			{
				offsetContent += method.programOffset(contentOfRegionScr,operationNum_r_fgfm,"r_fgfm","","face",offsetValue,true,"",isRotate);
			}			
		}
		else
		{
			offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_eg,"f_eg","","face",offsetValue,true,"",isRotate);
		}		
	}
	string judgeSentence1 = kindsOfTool+"." + operation + ".f_cg.cg_eg_both\", 1";
	string judgeSentence2 = kindsOfTool+"." + operation + ".f_cg.cg_eg_both\", 2";
	string judgeSentence = judgeSentence1 + "||" +judgeSentence2 ;
	offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_cg,"f_cg","","face",offsetValue,true,judgeSentence,isRotate);
    return offsetContent;
}

string CodeOffset::h_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{
            offsetContent ="";
			offsetValue = (value - T_valueOfCode) / 1;
	offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_eg,"f_eg",".eg_a_offset","",offsetValue,true,"",isRotate);
	offsetValue = -(value - T_valueOfCode) / 1;
	string judgeSentence1 = kindsOfTool+"." + operation + ".f_cg.cg_eg_both\", 1";
	string judgeSentence2 = kindsOfTool+"." + operation + ".f_cg.cg_eg_both\", 2";
	string judgeSentence = judgeSentence1 + "||" +judgeSentence2 ;
	offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_cg,"f_cg","face","",offsetValue,true,judgeSentence,isRotate);
    return offsetContent;          
}

string CodeOffset::e4_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{
            offsetContent ="";
			offsetValue = (value - T_valueOfCode)*7 ;
			string judgeSentence = kindsOfTool+"." + operation + ".f_cg.cg_eg_both\", 0";
			offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_cg,"f_cg",".cr_a_offset","",offsetValue,true,judgeSentence,isRotate);
            return offsetContent;
}

string CodeOffset::dI_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{
            offsetContent = "";
            offsetValue = -(value - T_valueOfCode) / 1;
            string get = "primaryValue=get(\""+kindsOfTool+".core_taper\");";
            string set = "set(\""+kindsOfTool+".core_taper\", primaryValue+"+ to_string(offsetValue) + ");";
            offsetContent = get + "\n" + set + "\n";
            return offsetContent;
}

string CodeOffset::HX_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{
	offsetContent ="";
	offsetValue = value - T_valueOfCode;
	if(operationNum_f_odcre.size()>0)
	{
		string judgeSentence = kindsOfTool+"." + operation + ".f_odcre.grd_section\", 1.000)";
		offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_odcre,"f_odcre","","face",offsetValue,true,judgeSentence,isRotate);
		
	}	
	else
	{
			offsetContent += method.rOffset(contentOfRegionScr,"r_infeed",offsetValue,"",isRotate,0,true);
	}

	return offsetContent;        
}

string CodeOffset::HZ_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{
	offsetContent = "";              
	offsetValue = value - T_valueOfCode;
                //operationNum = method.findOperationNum(contentOfRegionScr, "f_odcre");
				
	if (operationNum_f_odcre.size() <= 0)
	{
		offsetContent += method.rOffset(contentOfRegionScr,"l_infeed",offsetValue,"",isRotate,0,true);
	}
	return offsetContent;                                         
}

string CodeOffset::beita_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{
            offsetContent = "";
            offsetValue = -(value - T_valueOfCode) / 1;
			if(method.isContain(contentOfRegionScr,"set(\""+kindsOfTool+".od_type\", 1.000)"))
            {
				offsetContent += "primaryValue=get(\""+kindsOfTool+".helix\");";
				offsetContent += "set(\""+kindsOfTool+".helix\", primaryValue+"  + to_string(offsetValue) + ");";
            }
            else
            {	
				if(value-T_valueOfCode!=0)
				{
					double h=1/(tan(value-T_valueOfCode));
					double od = 0.0;
					od = atof(method.getTheNum(contentOfRegionScr, "set(\""+kindsOfTool+".tool_od\", ",  "," ,  ")").c_str());
					offsetValue = 3.1415926 * od* h;
					offsetContent += "primaryValue=get(\""+kindsOfTool+".abs_lead\");";
					offsetContent += "set(\""+kindsOfTool+".abs_lead\", primaryValue+"  + to_string(offsetValue) + ");";
				}				
            }          
            return offsetContent;
}

string CodeOffset::pai_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{
            offsetContent = "";
            offsetValue = -(value - T_valueOfCode) / 1;
            offsetContent += "primaryValue=get(\""+kindsOfTool+".abs_shear\");";
            offsetContent += "set(\""+kindsOfTool+".abs_shear\", primaryValue+" + to_string(offsetValue) + ");";
            return offsetContent;
}

string CodeOffset::b_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{
                offsetContent = "";
				offsetValue = -(value - T_valueOfCode);
                int num = method.numOfTooth(contentOfRegionScr);
                if (num % 2 != 0)
                {
					string judgeSentence1 = kindsOfTool+"." + operation + ".f_eg.walk_gash_rad\", 1";
					string parameter = kindsOfTool+"." + operation + ".f_eg.walk_length\", 0";
					offsetContent += method.getSeriesValue(contentOfRegionScr,operationNum_f_eg,"f_eg",parameter,offsetValue,judgeSentence1,isRotate);
					if (operationNum_f_cg.size()>0)
					{
						string judgeSentence2 = kindsOfTool+"." + operation + ".f_cg.cg_eg_both\", 1)";
						string judgeSentence3 = kindsOfTool+"." + operation + ".f_cg.cg_eg_both\", 2)";
						string judgeSentence = judgeSentence2 + "||" +judgeSentence3 ;
						parameter = kindsOfTool+"." + operation + ".f_cg.walk_length\", 0";
						offsetContent += method.getSeriesValue(contentOfRegionScr,operationNum_f_cg,"f_cg",parameter,offsetValue,judgeSentence,isRotate);
					}
                }
                return offsetContent;
}
string CodeOffset::Lf_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{
            offsetContent ="";
            offsetValue = -(value - T_valueOfCode) / 1;
			offsetContent += "primaryValue=get(\""+kindsOfTool+".fg_length\");";
			offsetContent += "set(\""+kindsOfTool+".fg_length\",primaryValue+" + to_string(offsetValue) + ");";
            return offsetContent;
}

string CodeOffset::L2_1_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{
            offsetContent = "";
            offsetValue = (value - T_valueOfCode) / 1;
            offsetContent += "primaryValue=get(\""+kindsOfTool+".l_infeed\");";
            offsetContent += "set(\""+kindsOfTool+".l_infeed\", primaryValue+"  + to_string(offsetValue) + ");";
			return offsetContent;
}
string CodeOffset::beita2_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{
            offsetContent = "";
            offsetValue = -(value - T_valueOfCode) / 1;          
	string judgeSentence1 = kindsOfTool+"." + operation + ".f_eg.walk_gash_rad\", 1";
	offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_eg,"f_eg",".eg_axial_rake","",offsetValue,true,judgeSentence1,isRotate);
	if (operationNum_f_cg.size()>0)
	{
		string judgeSentence2 = kindsOfTool+"." + operation + ".f_cg.cg_eg_both\", 1)";
		string judgeSentence3 = kindsOfTool+"." + operation + ".f_cg.cg_eg_both\", 2)";
		string judgeSentence = judgeSentence2 + "||" +judgeSentence3 ;	
		offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_cg,"f_cg",".axial_rake","",offsetValue,true,judgeSentence,isRotate);
	}
	return offsetContent;
}

string CodeOffset::j_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{
            offsetContent = "";
			offsetValue = (value - T_valueOfCode) / 1;
			offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_ed_nch,"f_ed_nch",".notch_y","",offsetValue,false,"",isRotate);
            return offsetContent;
}
string CodeOffset::seita_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{
                offsetContent ="";
				if(method.isContain(contentOfRegionScr,"(\""+kindsOfTool+".variable_space\", true)"))
                {
                    double seriesValue = 0;                    
                    offsetValue = -(value - T_valueOfCode);
                    seriesValue = method.getSeriesValue(contentOfRegionScr, "\""+kindsOfTool+".a_orient\", 1");
					offsetContent += "setSeriesValue(\""+kindsOfTool+".a_orient\",1,"  + to_string(seriesValue + offsetValue) + ");";  
                }
              
                else
                {
					offsetValue = (value - T_valueOfCode) / 1;
					string content = method.programOffset(contentOfRegionScr,operationNum_f_fg,"f_fg","","a",offsetValue,true,"",isRotate);
					int num = content.find("WheelOffset"); 
					while (num)
					{
						content.replace(num,11,"ToolOffset");
						num = content.find("WheelOffset");
					}
					offsetContent += content;
                }
                return offsetContent;
}
string CodeOffset::L1_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{
                offsetContent ="";
                offsetValue = -(value - T_valueOfCode) / 1;
				if(operationNum_f_od.size()>0)
                {
					if(operationNum_r_fg_lnd.size()>0)
                    {
						offsetContent += "primaryValue=get(\""+kindsOfTool+".od_length\");";
						offsetContent += "set(\""+kindsOfTool+".od_length\", primaryValue+"  + to_string(offsetValue) + ");";
						offsetContent += method.programOffset(contentOfRegionScr,operationNum_r_fg_lnd,"r_fg_lnd",".fg_lnd_length","",offsetValue,true,"",isRotate);

                    }
					else if(operationNum_r_od_bk.size()>0)
                    {
						offsetContent += "primaryValue=get(\""+kindsOfTool+".od_length\");";
						offsetContent += "set(\""+kindsOfTool+".od_length\", primaryValue+"  + to_string(offsetValue) + ");";
						offsetContent += method.programOffset(contentOfRegionScr,operationNum_r_od_bk,"r_od_bk",".end_position","",offsetValue,true,"",isRotate);
                    }
                    else
                    {
						offsetContent += "primaryValue=get(\""+kindsOfTool+".od_length\");";
						offsetContent += "set(\""+kindsOfTool+".od_length\", primaryValue+" + to_string(offsetValue) + ");";

                    }
                }                           
                return offsetContent;
}

string CodeOffset::k_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{
           
                offsetContent = "";
                offsetValue = -(value - T_valueOfCode) / 1;
				offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_ed_nch,"f_ed_nch",".notch_depth","",offsetValue,true,"",isRotate);
				return offsetContent;
}
string CodeOffset::m_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{
                offsetContent = "";
                offsetValue = -(value - T_valueOfCode) / 1;
				offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_ed_nch,"f_ed_nch",".walk_len","",offsetValue,true,"",isRotate);
                return offsetContent;
}


string CodeOffset::Dc3_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{
                offsetContent ="";
				if(operationNum_f_od.size()>0)
                {
					string judgeSentence = kindsOfTool+"." + operation + ".f_od.eccentric_not_straight\", 1.000)"; 					
					offsetValue = -(value - T_valueOfCode) / 2;
					offsetContent = method.programOffset(contentOfRegionScr,operationNum_f_od,"f_od","","radial",offsetValue,true,judgeSentence,isRotate);
					if(offsetContent == "")
					{						
						offsetValue = (value - T_valueOfCode) / 2;
						offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_od,"f_od","","face",offsetValue,true,"",isRotate);
					}				
                }
				else if(operationNum_f_odcre.size()>0)
                {
                    offsetValue = (value - T_valueOfCode) / 2;
					string judgeSentence1 = kindsOfTool+"." + operation + ".f_odcre.grd_section\", 0.000";
					string judgeSentence2 = kindsOfTool+"." + operation + ".f_odcre.grd_section\", 2.000";
					string judgeSentence = judgeSentence1 + "||" +judgeSentence2 ;	
					offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_odcre,"f_odcre","","face",offsetValue,true,judgeSentence,isRotate);
                }
                else
                {  
					offsetContent = method.getSteptoolsString(contentOfRegionScr, "st_profile.r_infeed", T_valueOfCode, value, 2,"",isRotate,false);
                }    
                return offsetContent;
}

string CodeOffset::f_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{
                offsetContent = "";
				if(operationNum_f_od.size()>0)
                {
					offsetValue = -(value - T_valueOfCode) / 10;
					string judgeSentence = kindsOfTool+"." + operation + ".f_od.eccentric_not_straight\", 1.000)";
					offsetContent = method.programOffset(contentOfRegionScr,operationNum_f_od,"f_od","","radial",offsetValue,true,judgeSentence,isRotate);
					if(offsetContent == "")
					{
						offsetValue = (value - T_valueOfCode) / 10;
						offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_od,"f_od","","face",offsetValue,true,judgeSentence,isRotate);
					}
                }
				else if(operationNum_f_odcre.size()>0)
                {
                    offsetValue = (value - T_valueOfCode) / 2;
					string judgeSentence1 = kindsOfTool+"." + operation + ".f_odcre.grd_section\", 0.000";
					string judgeSentence2 = kindsOfTool+"." + operation + ".f_odcre.grd_section\", 2.000";
					string judgeSentence = judgeSentence1 + "||" +judgeSentence2 ;	
					offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_odcre,"f_odcre","","face",offsetValue,true,judgeSentence,isRotate);
                }
                else
                {
					offsetContent = method.getSteptoolsString(contentOfRegionScr, "st_profile.r_infeed", T_valueOfCode, value, 10,"",isRotate,false);
                }            
                return offsetContent;
}

string CodeOffset::f1_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{           
                offsetContent = "";
                string get ;
                string set ;
				if (operationNum_r_fgfm.size() >= 2)
                {
					operation = to_string(operationNum[1]);
                    offsetValue = (value - T_valueOfCode);
                    get = "primaryValue=getWheelOffset(\""+kindsOfTool+"." + operation + ".f_fgfm\", \"face\");";
                    set = "setWheelOffset(\""+kindsOfTool+"." + operation + ".f_fgfm\", \"face\"," + "primaryValue+" + to_string(offsetValue) + " );";
                    offsetContent = get + "\n"+set+"\n";
                }
                else
                {
					if (operationNum_r_fg_lnd.size() > 0)
                    {
						offsetValue = -(value - T_valueOfCode);
						offsetContent += method.programOffset(contentOfRegionScr,operationNum_r_fg_lnd,"r_fg_lnd",".raised_land","",offsetValue,true,"",isRotate);
						offsetContent += method.programOffset(contentOfRegionScr,operationNum_r_fg_lnd,"r_fg_lnd",".shank_raised_land","",offsetValue,true,"",isRotate);

                    }
                    else
                    {
						if (operationNum_r_od_bk.size() > 0)
                        {
							offsetValue = (value - T_valueOfCode);
							offsetContent += method.programOffset(contentOfRegionScr,operationNum_r_od_bk,"r_od_bk","","face",true,offsetValue,"",isRotate);
                        }
                        else
                        {
							if(operationNum_r_fgfm.size()>0)
                            {
                                offsetContent += "";
                            }
                            else
                            {
								offsetValue = (value - T_valueOfCode);
								offsetContent += method.programOffset(contentOfRegionScr,operationNum_r_fg,"r_fg",".eot_fg_clr","",offsetValue,true,"",isRotate);
								offsetContent += method.programOffset(contentOfRegionScr,operationNum_r_fg,"r_fg",".shank_fg_clr","",offsetValue,true,"",isRotate);
                            }
                        }                 
                    }
                
                }                               
                    return offsetContent;
}

string CodeOffset::f2_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{       
                offsetContent = "";
				if(operationNum_f_od.size()>0)
                {
					offsetValue = (value - T_valueOfCode) / 3;
					string judgeSentence = kindsOfTool+"." + operation + ".f_od.pri_or_sec\", 2.000)";
					offsetContent = method.programOffset(contentOfRegionScr,operationNum_f_od,"f_od","","face",offsetValue,true,judgeSentence,isRotate);
					if(offsetContent == "")
					{
						offsetValue = -(value - T_valueOfCode);
						judgeSentence = kindsOfTool+"." + operation + ".f_od.pri_or_sec\", 0.000)";
						offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_od,"f_od",".od_pri_land_fn","",offsetValue,true,judgeSentence,isRotate);	
					}					
                }
				else if(operationNum_f_odcre.size()>0)
                {
                    offsetValue = (value - T_valueOfCode) / 2;
					string judgeSentence1 = kindsOfTool+"." + operation + ".f_odcre.grd_section\", 0.000";
					string judgeSentence2 = kindsOfTool+"." + operation + ".f_odcre.grd_section\", 2.000";
					string judgeSentence = judgeSentence1 + "||" +judgeSentence2 ;	
					offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_odcre,"f_odcre","","face",offsetValue,true,judgeSentence,isRotate);
                }
                else
                {
					operationNum=method.findOperationNums(contentOfRegionScr,"f_steptools");
					string profile ="profile" ;
					string judgeSentence = kindsOfTool+"." + operation + ".f_steptools." + profile + ".st_profile.pri_relief_selection\", true)";
					offsetContent += method.getSteptoolsString(contentOfRegionScr,"st_profile.pri_land",T_valueOfCode,value,1,judgeSentence,isRotate,false);
					if(offsetContent == "")
					{
						offsetContent += method.getSteptoolsString(contentOfRegionScr,"st_profile.pri_land",T_valueOfCode,value,3,judgeSentence,isRotate,false);
					}					
                }
                return offsetContent;
}

string CodeOffset::a_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{
                offsetContent = "";
				string judgeSentence1 = kindsOfTool+"." + operation + ".f_cg.cg_eg_both\", 1";
				string judgeSentence2 = kindsOfTool+"." + operation + ".f_cg.cg_eg_both\", 2";
				string judgeSentence = judgeSentence1 + "||" +judgeSentence2 ;	
				int num = method.numOfTooth(contentOfRegionScr);
				if(num % 2 ==0)
				{
					offsetValue = (value - T_valueOfCode);
					offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_eg,"f_eg","","radial",offsetValue,true,"",isRotate);
					if (operationNum_f_cg.size()>0)
					{						
						offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_cg,"f_cg","","radial",offsetValue,true,judgeSentence,isRotate);
					}
				}
				else
				{
					offsetValue = (value - T_valueOfCode) / (-1.5);
					offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_eg,"f_eg","","face",offsetValue,true,"",isRotate);
					if (operationNum_f_cg.size()>0)
					{
						offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_cg,"f_cg","","face",offsetValue,true,judgeSentence,isRotate);
					}
				}
                return offsetContent;
}

string CodeOffset::S1_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{
                offsetContent = "";
				string judgeSentence1 = kindsOfTool+"." + operation + ".f_cg.cg_eg_both\", 1";
				string judgeSentence2 = kindsOfTool+"." + operation + ".f_cg.cg_eg_both\", 2";
				string judgeSentence = judgeSentence1 + "||" +judgeSentence2 ;	
				int num = method.numOfTooth(contentOfRegionScr);
				offsetValue = -(value - T_valueOfCode)*0.6;
				if(num % 2 ==0)
				{					
					offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_eg,"f_eg","","radial",offsetValue,true,"",isRotate);
					if (operationNum_f_cg.size()>0)
					{						
						offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_cg,"f_cg","","radial",offsetValue,true,judgeSentence,isRotate);
					}
				}
				else
				{					
					offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_eg,"f_eg","","radial",offsetValue,true,"",isRotate);
					if (operationNum_f_cg.size()>0)
					{
						offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_cg,"f_cg","","radial",offsetValue,true,judgeSentence,isRotate);
					}
				}
                return offsetContent;      
}

string CodeOffset::aerfa3_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{        
                offsetContent = "";
                offsetValue = -(value - T_valueOfCode) ;
				if(operationNum_f_ed.size()>0)
				{
					offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_ed,"f_ed",".ed_pri","",offsetValue,true,"",isRotate);
				}
				else
				{
					offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_odcre,"f_odcre",".cr_ed_pri","",offsetValue,true,"",isRotate);
				}
                return offsetContent;
}

string CodeOffset::f3_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{
    offsetContent = "";				
	if(operationNum_f_ed.size()>0)
	{
		string judgeSentence = kindsOfTool+"." + operation + ".f_ed.pri_or_sec\", 0.000)";
		offsetValue = -(value - T_valueOfCode);
		offsetContent = method.programOffset(contentOfRegionScr,operationNum_f_ed,"f_ed",".ed_land","",offsetValue,true,judgeSentence,isRotate);
		if (offsetContent == "")
		{
			judgeSentence = kindsOfTool+"." + operation + ".f_ed.pri_or_sec\", 2.000)";
			offsetValue = (value - T_valueOfCode)/3;
			offsetContent = method.programOffset(contentOfRegionScr,operationNum_f_ed,"f_ed","","face",offsetValue,true,judgeSentence,isRotate);
		}
	}
	else
	{
		string judgeSentence = kindsOfTool+"." + operation + ".f_ed.pri_or_sec\", 0.000)";
		offsetValue = -(value - T_valueOfCode) ;
		offsetContent = method.programOffset(contentOfRegionScr,operationNum_f_odcre,"f_odcre","","radial",offsetValue,true,judgeSentence,isRotate);
		if (offsetContent == "")
		{
			judgeSentence = kindsOfTool+"." + operation + ".f_ed.pri_or_sec\", 2.000)";
			offsetValue = -(value - T_valueOfCode) / 3;
			offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_odcre,"f_odcre",".cr_ed_pri_land","",offsetValue,true,judgeSentence,isRotate);
		}
	}
	return offsetContent;
}

string CodeOffset::d6_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{
                offsetContent = "";
				if(operationNum_r_od_bk.size()>0)
                {
					offsetValue = -(value - T_valueOfCode) / 2;
					offsetContent += method.programOffset(contentOfRegionScr,operationNum_r_od_bk,"r_od_bk","","radial",offsetValue,true,"",isRotate);
                }
				else if(operationNum_r_fg_lnd.size()>0)
                {
					offsetValue = -(value - T_valueOfCode) / 2;
					offsetContent += method.programOffset(contentOfRegionScr,operationNum_r_fg_lnd,"r_fg_lnd","","radial",offsetValue,true,"",isRotate);
                }
                else 
                {
                    offsetValue = -(value - T_valueOfCode) / 1;
					offsetContent += method.programOffset(contentOfRegionScr,operationNum_r_fg,"r_fg",".eot_fg_clr","",offsetValue,true,"",isRotate);
					offsetContent += method.programOffset(contentOfRegionScr,operationNum_r_fg,"r_fg",".shank_fg_clr","",offsetValue,true,"",isRotate);
                }

                return offsetContent;
}

string CodeOffset::aerfa4_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{
                offsetContent = "";
                offsetValue = -(value - T_valueOfCode);
				if(operationNum_f_ed.size()>0)
                {
					string judgeSentence1 = kindsOfTool+"." + operation + ".f_odcre.pri_or_sec\", 0";
					string judgeSentence2 = kindsOfTool+"." + operation + ".f_odcre.pri_or_sec\", 2";
					string judgeSentence = judgeSentence1 + "||" +judgeSentence2 ;	
					offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_odcre,"f_odcre","cr_ed_sec","",offsetValue,true,judgeSentence,isRotate);
                }
				if (operationNum_f_odcre.size()>0)
				{
					string judgeSentence1 = kindsOfTool+"." + operation + ".f_ed.pri_or_sec\", 0";
					string judgeSentence2 = kindsOfTool+"." + operation + ".f_ed.pri_or_sec\", 2";
					string judgeSentence = judgeSentence1 + "||" +judgeSentence2 ;	
					offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_ed,"f_ed","ed_sec","",offsetValue,true,judgeSentence,isRotate);
				}
                return offsetContent;        
        }

string CodeOffset::gAL_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
        {
                offsetContent = "";
				string judgeSentence1 = kindsOfTool+"." + operation + ".f_cg.cg_eg_both\", 1";
				string judgeSentence2 = kindsOfTool+"." + operation + ".f_cg.cg_eg_both\", 2";
				string judgeSentence3 = kindsOfTool+"." + operation + ".f_eg.walk_gash_rad\", 1.000";
				string judgeSentence = judgeSentence1 + "||" +judgeSentence2 ;
				offsetValue = -(value - T_valueOfCode);
				int num = method.numOfTooth(contentOfRegionScr);
				if(num % 2 ==0)
				{
					offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_eg,"f_eg",".long_gash_angle","",offsetValue,true,judgeSentence3,isRotate);
					if (operationNum_f_cg.size()>0)
					{						
						offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_cg,"f_cg",".long_gash_angle","",offsetValue,true,judgeSentence,isRotate);
					}
				}
				else
				{
					string parameter = kindsOfTool+"." + operation + ".f_eg.gash_angle_with_dish\", 0";
					offsetContent += method.getSeriesValue(contentOfRegionScr,operationNum_f_eg,"f_eg",parameter,offsetValue,judgeSentence3,isRotate); 
					if (operationNum_f_cg.size()>0)
					{					
						parameter = kindsOfTool+"." + operation + ".f_cg.gash_angle_with_dish\", 0";
						offsetContent += method.getSeriesValue(contentOfRegionScr,operationNum_f_cg,"f_cg",parameter,offsetValue,judgeSentence,isRotate);						
					}
				}
                return offsetContent;
}

string CodeOffset::gAS_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{
                offsetContent = "";
				string judgeSentence1 = kindsOfTool+"." + operation + ".f_cg.cg_eg_both\", 1";
				string judgeSentence2 = kindsOfTool+"." + operation + ".f_cg.cg_eg_both\", 2";
				string judgeSentence3 = kindsOfTool+"." + operation + ".f_eg.walk_gash_rad\", 1.000";
				string judgeSentence = judgeSentence1 + "||" +judgeSentence2 ;
				offsetValue = -(value - T_valueOfCode);
				int num = method.numOfTooth(contentOfRegionScr);
				if(num % 2 ==0)
				{
					offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_eg,"f_eg",".short_gash_angle","",offsetValue,true,judgeSentence3,isRotate);
					if (operationNum_f_cg.size()>0)
					{						
						offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_cg,"f_cg",".short_gash_angle","",offsetValue,true,judgeSentence,isRotate);
					}
				}
				else
				{
					string parameter = kindsOfTool+"." + operation + ".f_eg.gash_angle_with_dish\", 0";
					offsetContent += method.getSeriesValue(contentOfRegionScr,operationNum_f_eg,"f_eg",parameter,offsetValue,judgeSentence3,isRotate); 
					if (operationNum_f_cg.size()>0)
					{					
						parameter = kindsOfTool+"." + operation + ".f_cg.gash_angle_with_dish\", 0";
						offsetContent += method.getSeriesValue(contentOfRegionScr,operationNum_f_cg,"f_cg",parameter,offsetValue,judgeSentence,isRotate);						
					}
				}
                return offsetContent;       
}

string CodeOffset::gAM_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{
                offsetContent = "";
				string judgeSentence1 = kindsOfTool+"." + operation + ".f_cg.cg_eg_both\", 1";
				string judgeSentence2 = kindsOfTool+"." + operation + ".f_cg.cg_eg_both\", 2";
				string judgeSentence3 = kindsOfTool+"." + operation + ".f_eg.walk_gash_rad\", 1.000";
				string judgeSentence = judgeSentence1 + "||" +judgeSentence2 ;
				offsetValue = -(value - T_valueOfCode);
				int num = method.numOfTooth(contentOfRegionScr);				
				offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_eg,"f_eg",".short_gash_angle","",offsetValue,true,judgeSentence3,isRotate);
				if (operationNum_f_cg.size()>0)
				{						
					offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_cg,"f_cg",".short_gash_angle","",offsetValue,true,judgeSentence,isRotate);
				}
				string parameter = kindsOfTool+"." + operation + ".f_eg.gash_angle_with_dish\", 0";
				offsetContent += method.getSeriesValue(contentOfRegionScr,operationNum_f_eg,"f_eg",parameter,offsetValue,judgeSentence3,isRotate); 
				if (operationNum_f_cg.size()>0)
				{					
					parameter = kindsOfTool+"." + operation + ".f_cg.gash_angle_with_dish\", 0";
					offsetContent += method.getSeriesValue(contentOfRegionScr,operationNum_f_cg,"f_cg",parameter,offsetValue,judgeSentence,isRotate);						
				}
                return offsetContent;
}

string CodeOffset::Dc4_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{
                offsetContent = "";
				offsetValue = (value - T_valueOfCode) / 2;
				if(operationNum_f_odcre.size()>0)
				{
					offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_odcre,"f_odcre","","face",offsetValue,true,"",isRotate);
				}
                return offsetContent;
}

string CodeOffset::d5_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{          
                offsetContent ="";
				offsetValue = (value - T_valueOfCode) / 0.02;
				if(operationNum_r_od_bk.size()>0)
				{
					offsetContent += method.programOffset(contentOfRegionScr,operationNum_r_od_bk,"r_od_bk",".od_obl_raised_land_pivot","",offsetValue,true,"",isRotate);
					offsetContent += method.programOffset(contentOfRegionScr,operationNum_r_fg,"r_fg",".eot_fg_clr","",offsetValue,true,"",isRotate);
					offsetContent += method.programOffset(contentOfRegionScr,operationNum_r_fg,"r_fg",".shank_fg_clr","",offsetValue,true,"",isRotate);
				}
				else
				{
					offsetContent += method.programOffset(contentOfRegionScr,operationNum_r_fg,"r_fg",".eot_fg_clr","",offsetValue,true,"",isRotate);
					offsetContent += method.programOffset(contentOfRegionScr,operationNum_r_fg,"r_fg_lnd",".shank_fg_clr","",offsetValue,true,"",isRotate);
					offsetContent += method.programOffset(contentOfRegionScr,operationNum_r_fg,"r_fg_lnd",".eot_fg_clr","",offsetValue,true,"",isRotate);
				}
                return offsetContent;                 
}

string CodeOffset::fa4_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{
                offsetContent = "";
				if(operationNum_f_odcre.size()<= 0)
				{
					offsetValue = (value - T_valueOfCode) / 3;
					offsetContent += method.rOffset(contentOfRegionScr,"l_infeed",offsetValue,"",isRotate,0,true);
				}
                return offsetContent;
}

string CodeOffset::fr4_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{         
    offsetContent = "";
	if(operationNum_f_odcre.size() > 0)
	{
		offsetValue = -(value - T_valueOfCode) ;
		string judgeSentence = kindsOfTool+"." + operation + ".f_odcre.grd_section\", 1.000)";
		offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_odcre,"f_odcre",".od_pri_land_fn","",offsetValue,true,judgeSentence,isRotate);
	}
	else
	{
		offsetValue = (value - T_valueOfCode) / 3;
		offsetContent += method.rOffset(contentOfRegionScr,"r_infeed",offsetValue,"",isRotate,0,true);
	}
	return offsetContent;       
}

string CodeOffset::r_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{
                offsetContent = "";
				operationNum=operationNum_f_odcre;
				if(operationNum.size()>0)
                {
					unsigned int index=0;
					offsetValue = -(value - T_valueOfCode) ;				                              					
					for (index = 0; index < operationNum.size(); index++)
                    {
						operation = to_string(operationNum[index]);
						if(is_T_Tool)
						{
							offsetContent += ("primaryValue=get(\""+kindsOfTool+"." +"cr_rad\"" + ");" + "\n"
												+ "set(\""+kindsOfTool+"." + "cr_rad\"," + "primaryValue+" + to_string(offsetValue) + " );"+"\n");
						}
						else
						{
							 offsetContent += ("primaryValue=getWheelOffset(\""+kindsOfTool+"." + operation + ".f_odcre\"," + "\"face\"" + ");" + "\n"
												+ "setWheelOffset(\""+kindsOfTool+"." + operation + ".f_odcre\", \"face\"," + "primaryValue+" + to_string(offsetValue) + " );"+"\n");
						}						                  
                    }
                }
                else
                {
					offsetValue = (value - T_valueOfCode) ;				
					string profile ;
					string Arc_strar;
					vector<vector<string>> stepStruct = method.getSteptoolStruct(contentOfRegionScr);
					for(int index=0;index<stepStruct[0].size()/2;index++ )
					{						
						operation=stepStruct[0][2*index];
						profile=stepStruct[0][2*index+1];
						Arc_strar = method.getTheNum(contentOfRegionScr,"addArcToGeometry(\""+kindsOfTool +"."+operation+".f_steptools."+ profile +".st_profile",",",4);
						if (Arc_strar == " 0.000")
						{										
							 string shank_to_eot=method.getTheNum(contentOfRegionScr,kindsOfTool +"."+operation+".f_steptools."+ profile +".st_profile.shank_to_eot",",",")");
							 double shank_to_eot_double =atof(shank_to_eot.c_str()); 
							vector<string> contentArr=method.contentArr;						
							int index;
							for(index=0;index<contentArr.size();index++)
							{
								if(method.isContain(contentArr[index],"clearGeometry(\""+kindsOfTool+"."+operation+".f_steptools."+profile+".st_profile\")"))break;
							}
							
							vector<string> splitStr1=method.split(contentArr[index+1],",");
							for(index;index<contentArr.size();index++)
							{
								if(method.isContain(contentArr[index],"addArcToGeometry(\"mill"))break;
							}
							vector<string> splitStr=method.split(contentArr[index],",");
							for(index;index<contentArr.size();index++)
							{
								if(!(method.isContain(contentArr[index],"add")))break;
							}

							double start_Arc_Angel = atof(splitStr[4].c_str());
							
							vector<string> split_Angel_end = method.split(splitStr[5],")");
							double end_Arc_Angel = atof(split_Angel_end[0].c_str());			
							vector<string> splitStr2=method.split(contentArr[index-1],",");					
							string centerX_new=to_string(atof(splitStr[1].c_str())+offsetValue);
							string centerY_new=to_string(atof(splitStr[2].c_str())+offsetValue);
							
						
							splitStr[1]=centerX_new;
							splitStr[2]=centerY_new;
							double r_region = atof(splitStr[3].c_str());
							double r_new = r_region - offsetValue ;
							splitStr[3]=to_string(r_new);
							string arc=splitStr[0]+", "+splitStr[1]+", "+splitStr[2]+","+splitStr[3]+","+splitStr[4]+","+splitStr[5]+";";
							if(shank_to_eot_double==0)
							{				
								splitStr1[3] = to_string(atof(centerX_new.c_str())+r_new*cos(start_Arc_Angel/180*pi));
								splitStr1[4] = to_string(atof(centerY_new.c_str())+r_new*sin(start_Arc_Angel/180*pi))+")";
								splitStr2[1] = to_string(atof(centerX_new.c_str())+r_new*cos((start_Arc_Angel+end_Arc_Angel)/180*pi));
								splitStr2[2] = to_string(atof(centerY_new.c_str())+r_new*sin((start_Arc_Angel+end_Arc_Angel)/180*pi));

							}
							else
							{
								splitStr1[1] = to_string(atof(centerX_new.c_str())+r_new*cos(start_Arc_Angel/180*pi));
								splitStr1[2] = to_string(atof(centerY_new.c_str())+r_new*sin(start_Arc_Angel/180*pi));
								splitStr2[3] = to_string(atof(centerX_new.c_str())+r_new*cos((start_Arc_Angel+end_Arc_Angel)/180*pi));
								splitStr2[4] = to_string(atof(centerY_new.c_str())+r_new*sin((start_Arc_Angel+end_Arc_Angel)/180*pi))+")";
						
							}
							string addline1=splitStr1[0]+", "+splitStr1[1]+", "+splitStr1[2]+","+splitStr1[3]+","+splitStr1[4]+";";
							string addline2=splitStr2[0]+", "+splitStr2[1]+", "+splitStr2[2]+","+splitStr2[3]+","+splitStr2[4]+";";
							offsetContent+="clearGeometry(\""+kindsOfTool+"."+operation+".f_steptools."+profile + ".st_profile\");\n"+addline1+"\n"
												+ arc +"\n"+addline2+"\n"+"executeOperationInstruction(\""+kindsOfTool+"."+operation+".f_steptools."+profile+".st_profile\", \"convertElementsToLeads\");\n";
								
						}
					}									
                }
				
                return offsetContent;
        
}
string CodeOffset::S2_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{
                offsetContent = "";
				int num = method.numOfTooth(contentOfRegionScr);
				string judgeSentence1 = kindsOfTool+"." + operation + ".f_eg.walk_gash_rad\", 1";
				string judgeSentence2 = kindsOfTool+"." + operation + ".f_eg.long_bottom_radius\", 0.000)";
				string judgeSentence = judgeSentence1 + "&&" +judgeSentence2 ;
				offsetValue = -(value - T_valueOfCode);
				if (num % 2 == 0)
                {
					offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_eg,"f_eg",".short_walk_length","",offsetValue,true,judgeSentence,isRotate);
				}
                else
                {
					string parameter = kindsOfTool+"." + operation + ".f_eg.walk_length\", 1";
					offsetContent += method.getSeriesValue(contentOfRegionScr,operationNum_f_eg,"f_eg",parameter,offsetValue,judgeSentence,isRotate);
				}				
				judgeSentence1 = kindsOfTool+"." + operation + ".f_cg.cg_eg_both\", 1";
				judgeSentence2 = kindsOfTool+"." + operation + ".f_cg.cg_eg_both\", 2";
				judgeSentence = judgeSentence1 + "||" +judgeSentence2 ;
				for(int index=0; index < operationNum_f_cg.size();index++)
				{
					if (method.isContain(contentOfRegionScr,".f_cg.cg_eg_both\", 1") || method.isContain(contentOfRegionScr,".f_cg.cg_eg_both\", 2"))
					{
						judgeSentence1 = kindsOfTool+"." + operation + ".f_cg.walk_standard_custom\", 1.000)";
						judgeSentence2 = kindsOfTool+"." + operation + ".f_cg.short_bottom_radius\", 0.000)";
						judgeSentence = judgeSentence1 + "&&" +judgeSentence2 ;
						if (num % 2== 0)
						{
							offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_cg,"f_cg",".short_walk_length","",offsetValue,true,judgeSentence,isRotate);
						}
						else
						{
							string parameter = kindsOfTool+"." + operation + ".f_cg.walk_length\", 1";
							offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_cg,"f_cg",parameter,"",offsetValue,true,judgeSentence,isRotate);
						}
					}
				}
                return offsetContent;
}

string CodeOffset::S3_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{
           
                offsetContent = "";
				int num = method.numOfTooth(contentOfRegionScr);
				string judgeSentence1 = kindsOfTool+"." + operation + ".f_eg.walk_gash_rad\", 1";
				string judgeSentence2 = kindsOfTool+"." + operation + ".f_eg.long_bottom_radius\", 0.000)";
				string judgeSentence = judgeSentence1 + "&&" +judgeSentence2 ;
				offsetValue = -(value - T_valueOfCode);
				if (num % 2 == 0)
                {
					offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_eg,"f_eg",".f_eg.long_walk_length","",offsetValue,true,judgeSentence,isRotate);
				}
                else
                {
					string parameter = kindsOfTool+"." + operation + ".f_eg.walk_length\", 1";
					offsetContent += method.getSeriesValue(contentOfRegionScr,operationNum_f_eg,"f_eg",parameter,offsetValue,judgeSentence,isRotate);
				}				
				judgeSentence1 = kindsOfTool+"." + operation + ".f_cg.cg_eg_both\", 1";
				judgeSentence2 = kindsOfTool+"." + operation + ".f_cg.cg_eg_both\", 2";
				judgeSentence = judgeSentence1 + "||" +judgeSentence2 ;
				for(int index=0; index < operationNum_f_cg.size();index++)
				{
					if (method.isContain(contentOfRegionScr,".f_cg.cg_eg_both\", 1") || method.isContain(contentOfRegionScr,".f_cg.cg_eg_both\", 2"))
					{
						judgeSentence1 = kindsOfTool+"." + operation + ".f_cg.walk_standard_custom\", 1.000)";
						judgeSentence2 = kindsOfTool+"." + operation + ".f_cg.short_bottom_radius\", 0.000)";
						judgeSentence = judgeSentence1 + "&&" +judgeSentence2 ;
						if (num % 2== 0)
						{
							offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_cg,"f_cg",".long_walk_length","",offsetValue,true,judgeSentence,isRotate);
						}
						else
						{
							string parameter = kindsOfTool+"." + operation + ".f_cg.walk_length\", 1";
							offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_cg,"f_cg",parameter,"",offsetValue,true,judgeSentence,isRotate);
						}
					}
				}
                return offsetContent;     
}


string CodeOffset::h1_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{
	offsetContent = "";
	offsetValue = -(value - T_valueOfCode);
	operationNum=method.findOperationNums(contentOfRegionScr,"f_cylindrical");
	if(operationNum.size()>0)
	{
		offsetContent += method.programOffset(contentOfRegionScr,operationNum,"f_cylindrical","","face",offsetValue,true,"",isRotate);
	}
	offsetContent += method.rOffset(contentOfRegionScr,"l_infeed",offsetValue,"",isRotate,1,true);
	return offsetContent;
}

string CodeOffset::N_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{
	offsetContent = "";
	string profile;
	offsetValue = (value - T_valueOfCode);
	operationNum=method.findOperationNums(contentOfRegionScr,"f_cylindrical");
	if(operationNum.size()>0)
	{
		offsetContent += method.programOffset(contentOfRegionScr,operationNum,"f_cylindrical","","face",offsetValue,true,"",isRotate);
	}
	else
	{		
		offsetValue = -(value - T_valueOfCode);
		offsetContent += method.rOffset(contentOfRegionScr,"r_infeed",offsetValue,"",isRotate,1,true);
	}
	return offsetContent;	
}

string CodeOffset::L2_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{
	offsetContent = "";
	offsetValue = -(value - T_valueOfCode);
	offsetContent = method.rOffset(contentOfRegionScr,"l_infeed",offsetValue,"",isRotate,1,true);
	return offsetContent;
}
string CodeOffset::L3_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{

	offsetContent=L2_Offset(contentOfRegionScr,T_valueOfCode,value);
	return offsetContent;

}

string CodeOffset::L4_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{

	offsetContent=L2_Offset(contentOfRegionScr,T_valueOfCode,value);
	return offsetContent;

}

string CodeOffset::lambdae_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{

	offsetContent = "";

	return offsetContent;

}

string CodeOffset::r1_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{

	offsetContent = "";
	return offsetContent;

}
string CodeOffset::L_1_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{	
	offsetContent = "";	
	if(operationNum_f_ed.size()>0)
	{
		string judgeSentence = kindsOfTool+"." + operation + ".f_ed.indiv_flute_option\", false)";
		offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_ed,"f_ed",".pri_long_stop_posn","",offsetValue,true,judgeSentence,isRotate);
		offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_ed,"f_ed",".pri_short_stop_posn","",offsetValue,true,judgeSentence,isRotate);
		if (offsetContent == "")
		{
			string judgeSentence = kindsOfTool+"." + operation + ".f_odcre.indiv_flute_option\", false)";
			offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_odcre,"f_odcre",".pri_long_stop_posn","",offsetValue,true,judgeSentence,isRotate);
			offsetContent += method.programOffset(contentOfRegionScr,operationNum_f_odcre,"f_odcre",".pri_short_stop_posn","",offsetValue,true,judgeSentence,isRotate);
		}
	}
	else
	{
		double seriesValue = 0;
		string operationName;
		int num=method.numOfTooth(contentOfRegionScr);
		if (operationNum_f_ed.size()>0)
		{
			operationName = "f_ed";
			operationNum = operationNum_f_ed;
		}
		else
		{
			operationName = "f_odcre" ;
			operationNum =operationNum_f_odcre;
		}
		for (int i = 0; i < operationNum.size(); i++)
		{			
				offsetContent += "angel=getToolOffset(\""+kindsOfTool+"." + operation + "." + operationName + "\"," + "\"a\"" + ");\n";				
				if (isRotate)
				{
					offsetContent += "if(angel > 10 && ange < -10) then\n\t";
				}
				else
				{
					offsetContent += "if(angel < 10 && angel > -10) then\n\t";
				}					
				for (int index = 0; index < num ; index++)
				{
					seriesValue =method.getSeriesValue(contentOfRegionScr,"\""+kindsOfTool+"."+operation+"."+operationName+".ed_pri_stop\", "+to_string(index));
					offsetContent += "setSeriesValue(\""+kindsOfTool+"." + operation + "."+operationName+".ed_pri_stop\"" + ","+ to_string(index) +"," + to_string(seriesValue + offsetValue) + ");";    
				}
		}		
	}
	return offsetContent;
}

string CodeOffset::f5_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{
	offsetContent = "";
	operationNum = method.findOperationNums(contentOfRegionScr,"f_steptools");
	offsetContent += method.rOffset(contentOfRegionScr,".rad_land",offsetValue,"",isRotate,0,false);
	return offsetContent;
}

string CodeOffset::fb_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{
	offsetContent = "";
	operationNum=method.findOperationNums(contentOfRegionScr,"f_cylindrical");
	offsetValue = -(value - T_valueOfCode);
	if(operationNum.size()>0)
	{
		offsetContent += method.rOffset(contentOfRegionScr,"l_infeed",offsetValue,"",isRotate,1,true);
	}
	else
	{
		operationNum=method.findOperationNums(contentOfRegionScr,"f_steptools");
		string profile ="profile" ;
		string judgeSentence = kindsOfTool+"." + operation + ".f_steptools." + profile + ".st_profile.pri_relief_selection\", true)";
		offsetContent += method.rOffset(contentOfRegionScr,"l_infeed",offsetValue,judgeSentence,isRotate,1,true);
	}
	return offsetContent;
}

string CodeOffset::JD_Offset(string contentOfRegionScr, double T_valueOfCode, double value)
{
	offsetContent = "";
	offsetValue = -(value - T_valueOfCode)/2;
	operationNum=method.findOperationNums(contentOfRegionScr,"f_cylindrical");
	if(operationNum.size()>0)
	{
		offsetContent += method.programOffset(contentOfRegionScr,operationNum,"f_cylindrical","","face",offsetValue,true,"",isRotate);
	}
	else
	{
		offsetValue = (value - T_valueOfCode)/2;
		offsetContent += method.rOffset(contentOfRegionScr,"r_infeed",offsetValue,"",isRotate,1,true);
	}
	return offsetContent;	

}



class ToolOffset
{
public:
	ToolOffset(string content,string codeStr);
	~ToolOffset(void);	
	Method method;
	CodeOffset* offset;
	vector<string> codes;
	string kindOfTool;
	string creatScrNewContent(string contentOfRegionScr, string code, double T_valueOfCode, double value);

};
ToolOffset::ToolOffset(string content,string codeStr)
{
	method.contentArr=method.split(content,";");
	
	kindOfTool=(method.getTheNum(content,"newTool","\"",""));
	
	method.kindOfTool=kindOfTool;
	offset=new CodeOffset(content,kindOfTool);
	offset->operationNum_f_od = method.findOperationNums(content,"f_od");
	offset->operationNum_f_cg = method.findOperationNums(content,"f_cg");
	offset->operationNum_f_eg = method.findOperationNums(content,"f_eg");
	offset->operationNum_f_ed = method.findOperationNums(content,"f_ed");
	offset->operationNum_f_ed_nch = method.findOperationNums(content,"f_ed_nch");
	offset->operationNum_f_fg= method.findOperationNums(content,"f_fg"); 
	offset->operationNum_f_odcre = method.findOperationNums(content,"f_odcre");
	offset->operationNum_r_fg = method.findOperationNums(content,"r_fg");
	offset->operationNum_r_fgfm = method.findOperationNums(content,"r_fgfm");
	offset->operationNum_r_fg_lnd = method.findOperationNums(content,"r_fg_lnd");
	offset->operationNum_r_od_bk = method.findOperationNums(content,"r_od_bk");
	
	offset->is_T_Tool=method.is_T_Tool(content);
	codes.push_back("d4");
	codes.push_back("delta");
	codes.push_back("beta1");
	codes.push_back("F");
	codes.push_back("alpha1");
	codes.push_back("e1");
	codes.push_back("a1");
	codes.push_back("e3");
	codes.push_back("alphaI");
	codes.push_back("alpha2");
	codes.push_back("J1");
	codes.push_back("S4");
	codes.push_back("lambda");
	codes.push_back("lambda_1");
	codes.push_back("Llambda");
	codes.push_back("e");
	codes.push_back("h");
	codes.push_back("e4");
	codes.push_back("dI");
	codes.push_back("HX");
	codes.push_back("HZ");
	codes.push_back("beta");
	codes.push_back("tau");
	codes.push_back("b");
	codes.push_back("Lf");
	codes.push_back("L2_1");
	codes.push_back("beta2");
	codes.push_back("j");
	codes.push_back("theta");
	codes.push_back("L1");
	codes.push_back("Dc3");
	codes.push_back("f");
	codes.push_back("f1");
	codes.push_back("f2");
	codes.push_back("a");
	codes.push_back("S1");
	codes.push_back("alpha3");
	codes.push_back("f3");
	codes.push_back("d6");
	codes.push_back("alpha4");
	codes.push_back("gAL");
	codes.push_back("gAS");
	codes.push_back("Dc4");
	codes.push_back("d5");
	codes.push_back("fa4");
	codes.push_back("fr4");
	codes.push_back("r");
	codes.push_back("S2");
	codes.push_back("S3");
	codes.push_back("gAM");
	codes.push_back("k");
	codes.push_back("m");
	codes.push_back("h1");
	codes.push_back("N");
	codes.push_back("L2");
	codes.push_back("L3");
	codes.push_back("L4");
	codes.push_back("r1");
	codes.push_back("L_1");
	codes.push_back("f5");
	codes.push_back("fb");
	codes.push_back("JD");

	codes.push_back("f1_fen");
}


ToolOffset::~ToolOffset(void)
{	
	delete offset;
}

string ToolOffset::creatScrNewContent(string contentOfRegionScr, string code, double T_valueOfCode, double value)
{
	
	unsigned int index=0;
	for(index=0;index<codes.size();index++)
	{
		if(code==codes[index])break;
	}	
	switch (index)
	{
		case 0: return offset->d4_Offset(contentOfRegionScr, T_valueOfCode, value);break;
        case 1: return offset->daozhui_Offset(contentOfRegionScr, T_valueOfCode, value);break;
        case 2: return offset->beita1_Offset(contentOfRegionScr, T_valueOfCode, value);break;
        case 3: return offset->F_Offset(contentOfRegionScr, T_valueOfCode, value);break;
        case 4: return offset->aerfa1_Offset(contentOfRegionScr, T_valueOfCode, value);break;
        case 5: return offset->e1_Offset(contentOfRegionScr, T_valueOfCode, value);break;
        case 6: return offset->a1_Offset(contentOfRegionScr, T_valueOfCode, value);break;
        case 7: return offset->e3_Offset(contentOfRegionScr, T_valueOfCode, value);break;
        case 8: return offset->aerfaI_Offset(contentOfRegionScr, T_valueOfCode, value);break;
        case 9: return offset->aerfa2_Offset(contentOfRegionScr, T_valueOfCode, value);break;
        case 10: return offset->J1_Offset(contentOfRegionScr, T_valueOfCode, value);break;
        case 11: return offset->S4_Offset(contentOfRegionScr, T_valueOfCode, value);break;
        case 12: return offset->lambda_Offset(contentOfRegionScr, T_valueOfCode, value);break;
        case 13: return offset->lambda_1_Offset(contentOfRegionScr, T_valueOfCode, value);break;
        case 14: return offset->Llambda_Offset(contentOfRegionScr, T_valueOfCode, value);break;
        case 15: return offset->e_Offset(contentOfRegionScr, T_valueOfCode, value);break;
        case 16: return offset->h_Offset(contentOfRegionScr, T_valueOfCode, value);break;
        case 17: return offset->e4_Offset(contentOfRegionScr, T_valueOfCode, value);break;
        case 18: return offset->dI_Offset(contentOfRegionScr, T_valueOfCode, value);break;
        case 19: return offset->HX_Offset(contentOfRegionScr, T_valueOfCode, value);break;
        case 20: return offset->HZ_Offset(contentOfRegionScr, T_valueOfCode, value);break;
        case 21: return offset->beita_Offset(contentOfRegionScr, T_valueOfCode, value);break;
        case 22: return offset->pai_Offset(contentOfRegionScr, T_valueOfCode, value);break;
        case 23: return offset->b_Offset(contentOfRegionScr, T_valueOfCode, value);break;
        case 24: return offset->Lf_Offset(contentOfRegionScr, T_valueOfCode, value);break;
        case 25: return offset->L2_1_Offset(contentOfRegionScr, T_valueOfCode, value);break;
        case 26: return offset->beita2_Offset(contentOfRegionScr, T_valueOfCode, value);break;
        case 27: return offset->j_Offset(contentOfRegionScr, T_valueOfCode, value);break;
        case 28: return offset->seita_Offset(contentOfRegionScr, T_valueOfCode, value);break;
        case 29: return offset->L1_Offset(contentOfRegionScr, T_valueOfCode, value);break;
        case 30: return offset->Dc3_Offset(contentOfRegionScr, T_valueOfCode, value);break;
        case 31: return offset->f_Offset(contentOfRegionScr, T_valueOfCode, value);break;
        case 32: return offset->f1_Offset(contentOfRegionScr, T_valueOfCode, value);break;
        case 33: return offset->f2_Offset(contentOfRegionScr, T_valueOfCode, value);break;
        case 34: return offset->a_Offset(contentOfRegionScr, T_valueOfCode, value);break;
        case 35: return offset->S1_Offset(contentOfRegionScr, T_valueOfCode, value);break;
        case 36: return offset->aerfa3_Offset(contentOfRegionScr, T_valueOfCode, value);break;
        case 37: return offset->f3_Offset(contentOfRegionScr, T_valueOfCode, value);break;
        case 38: return offset->d6_Offset(contentOfRegionScr, T_valueOfCode, value);break;
        case 39: return offset->aerfa4_Offset(contentOfRegionScr, T_valueOfCode, value);break;
        case 40: return offset->gAL_Offset(contentOfRegionScr, T_valueOfCode, value);break;
        case 41: return offset->gAS_Offset(contentOfRegionScr, T_valueOfCode, value);break;
        case 42: return offset->Dc4_Offset(contentOfRegionScr, T_valueOfCode, value);break;
        case 43: return offset->d5_Offset(contentOfRegionScr, T_valueOfCode, value);break;
        case 44: return offset->fa4_Offset(contentOfRegionScr, T_valueOfCode, value);break;
        case 45: return offset->fr4_Offset(contentOfRegionScr, T_valueOfCode, value);break;
        case 46: return offset->r_Offset(contentOfRegionScr, T_valueOfCode, value);break;
        case 47: return offset->S2_Offset(contentOfRegionScr, T_valueOfCode, value);break;
        case 48: return offset->S3_Offset(contentOfRegionScr, T_valueOfCode, value);break;
        case 49: return offset->gAM_Offset(contentOfRegionScr, T_valueOfCode, value);break;
        case 50: return offset->k_Offset(contentOfRegionScr, T_valueOfCode, value);break;
        case 51: return offset->m_Offset(contentOfRegionScr, T_valueOfCode, value);break;
		case 52: return offset->h1_Offset(contentOfRegionScr, T_valueOfCode, value);break;
		case 53: return offset->N_Offset(contentOfRegionScr, T_valueOfCode, value);break;
		case 54: return offset->L2_Offset(contentOfRegionScr, T_valueOfCode, value);break;
		case 55: return offset->L3_Offset(contentOfRegionScr, T_valueOfCode, value);break;
		case 56: return offset->L4_Offset(contentOfRegionScr, T_valueOfCode, value);break;
		case 57: return offset->r1_Offset(contentOfRegionScr, T_valueOfCode, value);break;
		case 58: return offset->L_1_Offset(contentOfRegionScr, T_valueOfCode, value);break;
		case 59: return offset->f5_Offset(contentOfRegionScr, T_valueOfCode, value);break;
		case 60: return offset->fb_Offset(contentOfRegionScr, T_valueOfCode, value);break;
		case 61: return offset->JD_Offset(contentOfRegionScr, T_valueOfCode, value);break;

		case 62: offset->isRotate =true; return offset->JD_Offset(contentOfRegionScr, T_valueOfCode, value);break;	
	default:
		return "";break;
	}	
}









class RelatedCodesOffset
{
public:
	RelatedCodesOffset(void);
	~RelatedCodesOffset(void);
	Method method;
	string offsetContent;
	double newValue;	
	vector<string> firstCodes;
	string getRelatedCodsOffset(string codes, string T_T_valueOfCode, string values, string contentOfRegionScr);
	bool isContain(vector<string> vec,string var);
	int findIndex(vector<string> vec,string var);
};
RelatedCodesOffset::RelatedCodesOffset(void)
{
	firstCodes.push_back("d4");
	firstCodes.push_back("delta");
	firstCodes.push_back("beta1");
	firstCodes.push_back("F");
	firstCodes.push_back("alpha1");
	firstCodes.push_back("a1");
	firstCodes.push_back("alphaI");
	firstCodes.push_back("alpha2");
	firstCodes.push_back("S4");
	firstCodes.push_back("lambda");
	firstCodes.push_back("lambda_1");
	firstCodes.push_back("Llambda");
	firstCodes.push_back("h");
	firstCodes.push_back("dI");
	firstCodes.push_back("b");
	firstCodes.push_back("Lf");
	firstCodes.push_back("L2_1");
	firstCodes.push_back("beta2");
	firstCodes.push_back("j");
	firstCodes.push_back("theta");
	firstCodes.push_back("L1");
	firstCodes.push_back("f");
	firstCodes.push_back("f1");
	firstCodes.push_back("f2");
	firstCodes.push_back("a");
	firstCodes.push_back("S1");
	firstCodes.push_back("alpha3");
	firstCodes.push_back("f3");
	firstCodes.push_back("d6");
	firstCodes.push_back("alpha4");
	firstCodes.push_back("d5");
	firstCodes.push_back("fa4");
	firstCodes.push_back("fr4");
	firstCodes.push_back("r");
	firstCodes.push_back("S2");
	firstCodes.push_back("S3");
	firstCodes.push_back("k");
	firstCodes.push_back("m");
}

RelatedCodesOffset::~RelatedCodesOffset(void)
{

}

string RelatedCodesOffset::getRelatedCodsOffset(string codes, string T_valueOfCode, string values, string contentOfRegionScr)
{
	ToolOffset offset(contentOfRegionScr,codes);
	method.contentArr=method.split(contentOfRegionScr,";");
	offsetContent="";
	vector<string> codesVector;
	vector<string> T_valueOfCodeVector;
	vector<string> valuesVector;

	if(method.isContain(codes,","))
	{
		codesVector=method.split(codes,",");
		T_valueOfCodeVector=method.split(T_valueOfCode,",");
		valuesVector=method.split(values,",");
	}
	else
	{	
		codesVector.push_back(codes);
		T_valueOfCodeVector.push_back(T_valueOfCode);
		valuesVector.push_back(values);
	}

	vector<int> operationNum ;
	string kindOfTool=(method.getTheNum(contentOfRegionScr,"newTool","\"",""));
	double offsetValue = 0;
	int indexOf_Dc3 = findIndex(codesVector,"Dc3");
	int indexOf_f3 = findIndex(codesVector,"f3");
	int indexOf_f2 = findIndex(codesVector,"f2");
	int indexOf_e1 = findIndex(codesVector,"e1");
	if (indexOf_e1 >= 0)
	{
		newValue=atof(valuesVector[indexOf_e1].c_str());

		offsetContent += offset.creatScrNewContent(contentOfRegionScr,codesVector[indexOf_e1], atof((T_valueOfCodeVector[indexOf_e1]).c_str()) , newValue);
		operationNum = method.findOperationNums(contentOfRegionScr,"f_cg");
		offsetValue = -(newValue - atof((T_valueOfCodeVector[indexOf_e1]).c_str()))/2;
		for (int index = 0; index < operationNum.size(); index++)
		{
			string operation = to_string(operationNum[index]);
			if(method.isContain(contentOfRegionScr,kindOfTool+"."+operation+"."+"f_cg"+"."+"cg_eg_both\", 0"))
			{
				offsetContent += "angel=getToolOffset(\""+kindOfTool+"." + operation + "." + "f_cg"+ "\"," + "\"a\"" + ");\n";
						offsetContent += "primaryValue=getWheelOffset(\""+kindOfTool+"." + operation + "." + "f_cg\"," + "\"face" + "\");" + "\n";		
				offsetContent += "if(angel < 10 && angel > -10) then\n\t";
				offsetContent += "setWheelOffset(\""+kindOfTool+"." + operation + "." + "f_cg\"" + ",\"face\"," + "primaryValue+" + to_string(offsetValue) + ");" + "\n";
				offsetContent += "ifend\n"; 
			}
		}
		operationNum = method.findOperationNums(contentOfRegionScr,"r_fg");
		if (operationNum.size()>0)
		{
			for (int index = 0; index < operationNum.size(); index++)
			{
				string operation = to_string(operationNum[index]);
				offsetContent += "angel=getToolOffset(\""+kindOfTool+"." + operation + "." + "r_fg"+ "\"," + "\"a\"" + ");\n";
							offsetContent += "primaryValue=getWheelOffset(\""+kindOfTool+"." + operation + "." + "r_fg\"," + "\"face" + "\");" + "\n";		
				offsetContent += "if(angel < 10 && angel > -10) then\n\t";
				offsetContent += "setWheelOffset(\""+kindOfTool+"." + operation + "." + "r_fg\"" + ",\"face\"," + "primaryValue+" + to_string(offsetValue) + ");" + "\n";
				offsetContent += "ifend\n"; 
			}
		}
		operationNum = method.findOperationNums(contentOfRegionScr,"r_fgfm");
		if (operationNum.size()>0)
		{
			for (int index = 0; index < operationNum.size(); index++)
			{
				string operation = to_string(operationNum[index]);
				offsetContent += "angel=getToolOffset(\""+kindOfTool+"." + operation + "." + "r_fgfm"+ "\"," + "\"a\"" + ");\n";
							offsetContent += "primaryValue=getWheelOffset(\""+kindOfTool+"." + operation + "." + "r_fgfm\"," + "\"face"+ "\");" + "\n";		
				offsetContent += "if(angel < 10 && angel > -10) then\n\t";
				offsetContent += "setWheelOffset(\""+kindOfTool+"." + operation + "." + "r_fgfm\"" + ",\"face\"," + "primaryValue+" + to_string(offsetValue) + ");" + "\n";
				offsetContent += "ifend\n"; 
			}
		}
		operationNum = method.findOperationNums(contentOfRegionScr,"f_fg");
		if (operationNum.size()>0)
		{
			for (int index = 0; index < operationNum.size(); index++)
			{
				string operation = to_string(operationNum[index]);
				offsetContent += "angel=getToolOffset(\""+kindOfTool+"." + operation + "." + "f_fg"+ "\"," + "\"a\"" + ");\n";
								offsetContent += "primaryValue=getWheelOffset(\""+kindOfTool+"." + operation + "." + "f_fg\"," + "\"face" + "\");" + "\n";		
				offsetContent += "if(angel < 10 && angel > -10) then\n\t";
				offsetContent += "setWheelOffset(\""+kindOfTool+"." + operation + "." + "f_fg\"" + ",\"face\"," + "primaryValue+" + to_string(offsetValue) + ");" + "\n";
				offsetContent += "ifend\n"; 
			}
		}	
		
			offsetContent += offset.creatScrNewContent(contentOfRegionScr,"Dc3", -atof((T_valueOfCodeVector[indexOf_e1]).c_str())/6.67 , -newValue/6.67);
			offsetContent += offset.creatScrNewContent(contentOfRegionScr,"HX", -atof((T_valueOfCodeVector[indexOf_e1]).c_str())/6.67 , -newValue/6.67);
			offsetContent += offset.creatScrNewContent(contentOfRegionScr,"f3", -atof((T_valueOfCodeVector[indexOf_e1]).c_str()) , -newValue);
			offsetContent += offset.creatScrNewContent(contentOfRegionScr,"f2", -atof((T_valueOfCodeVector[indexOf_e1]).c_str()) , -newValue);
	}
	
	

	int indexOf_e3 = findIndex(codesVector,"e3");
	if (indexOf_e3 >= 0 )
	{
		operationNum = method.findOperationNums(contentOfRegionScr,"f_cg");
		offsetValue = (atof(valuesVector[indexOf_e3].c_str())-atof((T_valueOfCodeVector[indexOf_e3]).c_str()))/7;
		newValue = atof(valuesVector[indexOf_e3].c_str());
		for (int index = 0; index < operationNum.size(); index++)
		{
			string operation = to_string(operationNum[index]);
			if(method.isContain(contentOfRegionScr,kindOfTool+"."+operation+"."+"f_cg"+"."+"cg_eg_both\", 0"))
			{
				offsetContent += "angel=getToolOffset(\""+kindOfTool+"." + operation + "." + "f_cg"+ "\"," + "\"a\"" + ");\n";
						offsetContent += "primaryValue=getWheelOffset(\""+kindOfTool+"." + operation + "." + "f_cg\"," + "\"face" + "\");" + "\n";		
				offsetContent += "if(angel < 10 && angel > -10) then\n\t";
				offsetContent += "setWheelOffset(\""+kindOfTool+"." + operation + "." + "f_cg\"" + ",\"face\"," + "primaryValue+" + to_string(offsetValue) + ");" + "\n";
				offsetContent += "ifend\n"; 
			}
		}

		operationNum = method.findOperationNums(contentOfRegionScr,"r_fg");
		if (operationNum.size()>0)
		{
			for (int index = 0; index < operationNum.size(); index++)
			{
				string operation = to_string(operationNum[index]);
				offsetContent += "angel=getToolOffset(\""+kindOfTool+"." + operation + "." + "r_fg"+ "\"," + "\"a\"" + ");\n";
							offsetContent += "primaryValue=getWheelOffset(\""+kindOfTool+"." + operation + "." + "r_fg\"," + "\"face" + "\");" + "\n";		
				offsetContent += "if(angel < 10 && angel > -10) then\n\t";
				offsetContent += "setWheelOffset(\""+kindOfTool+"." + operation + "." + "r_fg\"" + ",\"face\"," + "primaryValue+" + to_string(offsetValue) + ");" + "\n";
				offsetContent += "ifend\n"; 
			}
		}

		operationNum = method.findOperationNums(contentOfRegionScr,"r_fgfm");
		if (operationNum.size()>0)
		{
			for (int index = 0; index < operationNum.size(); index++)
			{
				string operation = to_string(operationNum[index]);
				offsetContent += "angel=getToolOffset(\""+kindOfTool+"." + operation + "." + "r_fgfm"+ "\"," + "\"a\"" + ");\n";
							offsetContent += "primaryValue=getWheelOffset(\""+kindOfTool+"." + operation + "." + "r_fgfm\"," + "\"face" + "\");" + "\n";		
				offsetContent += "if(angel < 10 && angel > -10) then\n\t";
				offsetContent += "setWheelOffset(\""+kindOfTool+"." + operation + "." + "r_fgfm\"" + ",\"face\"," + "primaryValue+" + to_string(offsetValue) + ");" + "\n";
				offsetContent += "ifend\n"; 
			}
		}
		operationNum = method.findOperationNums(contentOfRegionScr,"f_fg");
		if (operationNum.size()>0)
		{
			for (int index = 0; index < operationNum.size(); index++)
			{
				string operation = to_string(operationNum[index]);
				offsetContent += "angel=getToolOffset(\""+kindOfTool+"." + operation + "." + "f_fg"+ "\"," + "\"a\"" + ");\n";
								offsetContent += "primaryValue=getWheelOffset(\""+kindOfTool+"." + operation + "." + "f_fg\"," + "\"face" + "\");" + "\n";		
				offsetContent += "if(angel < 10 && angel > -10) then\n\t";
				offsetContent += "setWheelOffset(\""+kindOfTool+"." + operation + "." + "f_fg\"" + ",\"face\"," + "primaryValue+" + to_string(offsetValue) + ");" + "\n";
				offsetContent += "ifend\n"; 
			}
		}	
			offsetContent += offset.creatScrNewContent(contentOfRegionScr,"Dc3", atof((T_valueOfCodeVector[indexOf_e3]).c_str())/86.71 , newValue/86.71);
			offsetContent += offset.creatScrNewContent(contentOfRegionScr,"HX", atof((T_valueOfCodeVector[indexOf_e3]).c_str())/86.71 , newValue/86.71);
			offsetContent += offset.creatScrNewContent(contentOfRegionScr,"f2", -atof((T_valueOfCodeVector[indexOf_e3]).c_str())/13 , -newValue/13);
	}
	int indexOf_e= findIndex(codesVector,"e");
	if (indexOf_e >= 0)
	{
		offsetValue = -(atof(valuesVector[indexOf_e].c_str())-atof((T_valueOfCodeVector[indexOf_e]).c_str()))/2;
		newValue = atof(valuesVector[indexOf_e].c_str());
		operationNum = method.findOperationNums(contentOfRegionScr,"r_fg");
		if (operationNum.size()>0)
		{
			for (int index = 0; index < operationNum.size(); index++)
			{
				string operation = to_string(operationNum[index]);
				offsetContent += "angel=getToolOffset(\""+kindOfTool+"." + operation + "." + "r_fg"+ "\"," + "\"a\"" + ");\n";
							offsetContent += "primaryValue=getWheelOffset(\""+kindOfTool+"." + operation + "." + "r_fg\"," + "\"face" + "\");" + "\n";		
				offsetContent += "if(angel < 10 && angel > -10) then\n\t";
				offsetContent += "setWheelOffset(\""+kindOfTool+"." + operation + "." + "r_fg\"" + ",\"face\"," + "primaryValue+" + to_string(offsetValue) + ");" + "\n";
				offsetContent += "ifend\n"; 
			}
		}

		operationNum = method.findOperationNums(contentOfRegionScr,"r_fgfm");
		if (operationNum.size()>0)
		{
			for (int index = 0; index < operationNum.size(); index++)
			{
				string operation = to_string(operationNum[index]);
				offsetContent += "angel=getToolOffset(\""+kindOfTool+"." + operation + "." + "r_fgfm"+ "\"," + "\"a\"" + ");\n";
							offsetContent += "primaryValue=getWheelOffset(\""+kindOfTool+"." + operation + "." + "r_fgfm\"," + "\"face" + "\");" + "\n";		
				offsetContent += "if(angel < 10 && angel > -10) then\n\t";
				offsetContent += "setWheelOffset(\""+kindOfTool+"." + operation + "." + "r_fgfm\"" + ",\"face\"," + "primaryValue+" + to_string(offsetValue) + ");" + "\n";
				offsetContent += "ifend\n"; 
			}
		}
		operationNum = method.findOperationNums(contentOfRegionScr,"f_fg");
		if (operationNum.size()>0)
		{
			for (int index = 0; index < operationNum.size(); index++)
			{
				string operation = to_string(operationNum[index]);
				offsetContent += "angel=getToolOffset(\""+kindOfTool+"." + operation + "." + "f_fg"+ "\"," + "\"a\"" + ");\n";
								offsetContent += "primaryValue=getWheelOffset(\""+kindOfTool+"." + operation + "." + "f_fg\"," + "\"face" + "\");" + "\n";		
				offsetContent += "if(angel < 10 && angel > -10) then\n\t";
				offsetContent += "setWheelOffset(\""+kindOfTool+"." + operation + "." + "f_fg\"" + ",\"face\"," + "primaryValue+" + to_string(offsetValue) + ");" + "\n";
				offsetContent += "ifend\n"; 
			}
		}
	
		offsetContent += offset.creatScrNewContent(contentOfRegionScr,"Dc3", -atof((T_valueOfCodeVector[indexOf_e]).c_str())/7 ,-newValue/7);		
		offsetContent += offset.creatScrNewContent(contentOfRegionScr,"HX", -atof((T_valueOfCodeVector[indexOf_e]).c_str())/7 ,-newValue/7);	
		offsetContent += offset.creatScrNewContent(contentOfRegionScr,"f2", -atof((T_valueOfCodeVector[indexOf_e]).c_str())/3 ,-newValue/3);
		int indexOf_e4 = findIndex(codesVector,"e4");
		offsetContent += offset.creatScrNewContent(contentOfRegionScr,"e4", -atof((T_valueOfCodeVector[indexOf_e]).c_str())*62, -newValue*62);
	}
	
	int indexOf_e4 = findIndex(codesVector,"e4");
	if (indexOf_e4 >= 0)
	{
		offsetContent += offset.creatScrNewContent(contentOfRegionScr,codesVector[indexOf_e4], atof((T_valueOfCodeVector[indexOf_e4]).c_str()), atof(valuesVector[indexOf_e4].c_str()));
	}
	int indexOf_S1 = findIndex(codesVector,"S1");
	if (indexOf_S1 < 0 )
	{
		int indexOf_J1 = findIndex(codesVector,"J1");
		if (indexOf_J1 >= 0)
		{
			offsetContent += offset.creatScrNewContent(contentOfRegionScr,"J1", atof((T_valueOfCodeVector[indexOf_J1]).c_str())*0.6, atof(valuesVector[indexOf_J1].c_str())*0.6);
		}
	}

	int indexOf_HX=findIndex(codesVector,"HX");
	if (indexOf_HX >=0 )
	{
		newValue = atof(valuesVector[indexOf_HX].c_str());
		if (newValue >= 0)
		{
			offsetContent += offset.creatScrNewContent(contentOfRegionScr,codesVector[indexOf_HX], atof((T_valueOfCodeVector[indexOf_HX]).c_str()) , newValue-0.005);
		}
		else
		{
			offsetContent += offset.creatScrNewContent(contentOfRegionScr,codesVector[indexOf_HX], atof((T_valueOfCodeVector[indexOf_HX]).c_str()) , newValue+0.005);
		}
	}
	int indexOf_HZ=findIndex(codesVector,"HZ");
	if (indexOf_HZ >=0 )
	{
		newValue = atof(valuesVector[indexOf_HZ].c_str());
		if (newValue >= 0)
		{
			offsetContent += offset.creatScrNewContent(contentOfRegionScr,codesVector[indexOf_HZ], atof((T_valueOfCodeVector[indexOf_HZ]).c_str()) , newValue-0.003);
		}
		else
		{
			offsetContent += offset.creatScrNewContent(contentOfRegionScr,codesVector[indexOf_HZ], atof((T_valueOfCodeVector[indexOf_HZ]).c_str()) , newValue+0.003);
		}
	}
	if (indexOf_Dc3 >= 0)
	{
		newValue = atof(valuesVector[indexOf_Dc3].c_str());
		offsetContent += offset.creatScrNewContent(contentOfRegionScr,codesVector[indexOf_Dc3], atof((T_valueOfCodeVector[indexOf_Dc3]).c_str()), newValue);
		offsetContent += offset.creatScrNewContent(contentOfRegionScr,"HX", atof((T_valueOfCodeVector[indexOf_Dc3]).c_str())/2 , newValue/2);		
	}
	for(unsigned int index=0;index<codesVector.size();index++)
	{
		for(unsigned int indexJ=0;indexJ<firstCodes.size();indexJ++)
		{
			if(codesVector[index]==firstCodes[indexJ])
			{
				offsetContent+=offset.creatScrNewContent(contentOfRegionScr, codesVector[index], atof((T_valueOfCodeVector[index]).c_str()) , atof((valuesVector[index]).c_str()));
			}
		}
	}	
	return offsetContent;
}







bool RelatedCodesOffset::isContain(vector<string> vec,string var)
{
	bool contains=false;
	for(unsigned int index=0;index<vec.size();index++)
	{
		if(vec[index]==var)
		{
			contains=true;
		}
	}
	return contains;
}
int RelatedCodesOffset::findIndex(vector<string> vec,string var)
{
	int index;
	for(index=0;index<vec.size();index++)
	{
		if(vec[index]==var)break;					
	}
	if(index<vec.size())
	{
		return index;
	}
	else
	{
		return -1;
	}
}



class AutoOffset
{
public:
	AutoOffset(void);
	~AutoOffset(void);
	string contentOfRegionScr;
	string offsetContent;
	Method method;
	RelatedCodesOffset myRelateOffset;
	string creatNewScr(string codes, string T_valueOfCode, string values,string scrPathOfRead);
};
AutoOffset::AutoOffset(void)
{
}


AutoOffset::~AutoOffset(void)
{

}
string AutoOffset::creatNewScr(string codes, string T_valueOfCode, string values,string scrPathOfRead)
{
	contentOfRegionScr= method.readScr(scrPathOfRead);
	offsetContent=myRelateOffset.getRelatedCodsOffset(codes,T_valueOfCode,values,contentOfRegionScr);
	return offsetContent;
}

















